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. Some are simpler than others in at least two different ways. The actions of some are completely specified on the command line that invokes them like all the above list except the last one, firefox. More elaborate ones continue to interact with you after they've started, and are sometimes called applications. Many, but not all, of these applications interact through a graphical interface, or GUI.

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

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 semicolon 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, while 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.

Access

Man pages are monolithic and some are quite long, and it's occasionally hard to find what you want. The tradeoff is that the man command automatically puts you in a pager that allows you to search for specific text, usually using key bindings like vi. This can be good if you know what to look for.

Info pages are usually subdivided, and contain some directory and hyperlink information. The tradeoff is that you need to be at least minimally familiar with the key bindings used for navigation. They are a subset of those for emacs. Alternatively, you can export the entire tree as a single text document and view through a pager with the command

$ info --subnodes command | less

this loses the hyperlinks, but you can use the same navigation skills you use on a man page.

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.

By name

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
  • apropos - search the manual page names and descriptions
  • apt-get - a package management frontend for Debian-based distributions
  • at - execute a command-line task at a specified future time
  • awk - print only the nth word of an input line and more

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
  • dig - show answer of DNS lookup of queried name server
  • disown - disowns a job (removes the pid of the job). Even when the shell exits, the job won't stop running
  • du - show how much disc space is used up

E

F

G

  • g++ - compile C++ code
  • gawk - This command is used to find text within files and replace it.
  • gcc - compile C code
  • getopts - Parse positional parameters
  • grep - grab for patterns in a file and more
  • groupadd - Use this command to add security user groups.
  • groupdel - This one is used for deleting a certain group.
  • groupmod - While the last one deletes, this one modified a group.
  • groups - show what groups your user is in
  • gunzip - unpack files from a special format
  • gzip - pack files in a special format

H

I

  • id - show your user and groups ids
  • ifconfig - show your ip address and more
  • info - show info about a given command
  • init - change runlevel
  • iptables - show your firewall configuration
  • iptraf - Interactive IP LAN monitor

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 files in a directory
  • lshal - list HAL devices
  • lshw - list hardware
  • lsmod - list loaded kernel modules
  • lsof - list open files and listening sockets
  • lspci - list all pci devices
  • lsusb - list usb devices

M

N

O

P

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 packet takes over the network
  • tac - print the file in reverse. (opposite of cat) (cat X tac)
  • tune2fs - adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems

U

  • ulimit - show the limits of your user
  • umount - unmount a device (Often requires sudo permissions)
  • uname - show the running kernel's version and more
  • uniq - remove repeated lines in a sorted file
  • unrar - extract .rar files
  • unzip - unpack files
  • uptime - show the time since your computer was last switched on
  • useradd - add a user
  • userdel - delete a user
  • usermod - modify a user

V

  • Vgcreate - create lvm volume groups
  • Vgdisplay - display lvm volume groups
  • Vgs - show information about lvm volume groups
  • Vgscan - scan for lvm volume groups
  • vim - a text editor, not entirely unlike Notepad, but more powerful and programmable.
  • Vmstat - show input/output values, swap, memory consumption and more

W

  • w - print who is logged in to your system
  • wc - word count (word,line,char)
  • wget - The non-interactive network downloader
  • whereis - locate the binary, source, and manual page files for a command
  • which - print the path where you find an executable file
  • who - see who is on the system
  • whoami - print your effective user name

X

Y

Z

By category

Links

See Also

External Links