Linux - Commands, Arguments, and Options
A command is a word that is typed at the terminal window prompt in order to perform some action. For example, the ls command is used to list the contents of a directory (specifically, the current directory). If you would like to view the contents of a different directory, then you can supply an argument to the ls command which is the location of the desired directory, e.g., ls /bin would display the contents of the /bin directory where /bin is the argument to the ls command.
In addition to arguments, many (most) *nix commands accept command options as well. Options are specified either with a hyphen followed by a letter, e.g., -l, or a pair of hyphens followed by a word, e.g., --help. For example, ls -l /usr/bin is a command (ls) with the option -l and the argument /usr/bin.
Options modify the way commands work. When no options are specified we would say that is the default behavior of the command. Options can be used to alter the default behavior. Note that like everything else in *nix, options are case sensitive. There is a difference between ls -l and ls –L as there is between ls and LS. A command can have multiple options, e.g., the ls command supports two options -l and -a that alter it in different ways. A legal ls command using these two options would be ls -a -l. But often times, options can be combined so this same command could be typed as ls -al and it would perform the same action.
A useful option you should know is --help. Many commands will display a screen of text describing the commands, its action, and its options and arguments in response to the --help option. Whitespace surrounding options is important. The command ls -a-l is erroneous because there is no space in between the -a and -l options. The correct command is ls-a-l. In conclusion, know that the general format of a *nix command is command options arguments—in that order.
No comments:
Post a Comment