View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > Command

From LQWiki

(Redirected from Commands)
Jump to: navigation, search

A command, in the most general sense, is an executable file or a shell builtin. For example, cd, ls, echo and firefox are commands.

Specifically for this section of the LQ Wiki, "commands" mean text-based tools rather than GUI tools which are covered in the Applications section.

Note: details of commands vary from version to version and available commands vary from distribution to distribution.

Contents

General notes on commands

Commands may be invoked as simple commands. In these examples, the $ that starts each line is a shell prompt and not meant to be typed

$ ls

Or they may be invoked as complex commands.

$ ls -l /bin

Here "-l /bin" are a pair of arguments (separated from each other and the command by whitespace) and "-l" is specifically an option, since it modifies the behavior of ls (it produces a long listing), while "/bin" simply specifies a target for ls to act on.

They may also be invoked in multiples where the semi-colon is a command separator.

$ cd /bin; ls

That's two commands on one line. You may also execute one long command on two lines by escaping the carriage return with a backslash. (See scripting for further details on metacharacters and escaping and quoting.)

$ cd really long command line \
that we would like to finish here

Another way to invoke multiple commands is conditionally, where (in bash) "&&" means to execute the second command only if the first returns with an exit code of 0 (i.e., it succeeds).

$ cd /bin && ls

With the semicolon command separator, had the change of directory failed, ls would still have been invoked and simply listed the contents of the current directory. With the conditional operator, ls would not be invoked if cd had failed.

Similarly, "||" means to execute the second command only if the first returns a non-zero exit code (i.e., it fails).

$ cd /bing 2>/dev/null || echo 'I kinna do it, Cap'\''n!'

This will cd to the directory named "bing" if it in fact exists and the command will exit. Since it probably doesn't, being a typo, the second command will execute and print a somewhat more entertaining error message than is usual.

Learning about commands with local documentation

A Linux system should have documentation in the form of man pages and possibly GNU info pages (see also texinfo). In a manner similar to this page's alphabetical list, if you know the command you wish to learn more about,

$ man command

will show you the manual page of command.

If you do not know the command but would like to see commands relevant to a topic, use

$ apropos subject

or

$ man -k subject

to find suitable commands.

Unfortunately, most man pages will be informative and complete, many GNU utilities distribute very sketchy man pages whose primary purpose is to redirect the user to the info system. In that case,

$ info command

will invoke that system of documentation.

Many commands have an "-h", "-H", "-help", "--help" option or some combination thereof. Unfortunately, some commands understand other things by "-h" or "-H" so unexpected and possibly unpleasant results may occur.

There are also extensive miscellaneous files usually found in /usr/doc, /usr/local/doc, /usr/src/linux/Documentation (kernel docs), and elsewhere.

Lists of commands

In our Category Command you will find all commands in this wiki, but without explanation. The next chapter lists the most relevant ones with a short explanation so you can decide if the respective command is right for you. If you add to this list, your contribution should be didactic, understandable for newcomers, focused on the "real world" and contain sensible examples.

What command is right for you

This is a list of commands that gives you just enough information to decide what command you want to use.

A

  • alias - allows you to create shorter or more familiar names for commonly used commands
  • at - execute a command-line task at a specified future time
  • apropos - give information to a command
  • awk - print only the nth word of an input line and more
  • aspell - interactive check the spell

B

C

D

  • date - output or set date and time
  • dd - dump a disk to/from a file and more
  • df - show how much free disk space there is
  • diff - show the difference between two files and more
  • du - show how much disc space is used up

E

F

G

H

I

J

K

L

  • ldd - show dynamic libraries needed by an executable
  • less - show output in a viewer where you can scroll and search
  • ln - link a file
  • ls - list a file
  • lsmod - list loaded kernel modules
  • lsof - list open files and listening sockets
  • look - quick spell check

M

N

O

P

  • passwd - change your and other's password
  • ping - show if a given computer is up and running
  • ps - show running processes
  • pwd - show your current working directory
  • paste - merge lines into a file by combining horizontlly

Q

  • quota - manage how much resources the user is allowed to consume

R

S

T

  • tail - show only the last n lines of a file and more
  • tar - pack files in a special format
  • tcpdump - dump the tcp network traffic
  • tee - multiplex cli output
  • time - show the time needed by a command to finish
  • top - show the top CPU consuming processes and more
  • touch - create a file or update its time stamp
  • traceroute - show the route a package takes over the network

U

V

W

  • w - print who is logged in to your system
  • which - print the path where you find an executable file
  • whoami - print your effective user name
  • wc - word count(word,line,char)

X

  • xargs - hand over stdin as a parameter
  • xev - show information about your keystrokes and more
  • xkill - kill a window that is in your way

Y

Z

By category



External links


Personal tools