Options

command [options…] [arguments…]
Options can be used to alter the behavior of a command. On the previous page, the ls command was used to list the contents of a directory. In the following example, the -l option is provided to the lscommand, which results in a "long display" output, meaning the output gives more information about each of the files listed
sysadmin@localhost:~$ ls -l
total 32
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Desktop
drwxr-xr-x 4 sysadmin sysadmin 4096 Aug  4 20:58 Documents
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Downloads
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Music
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Pictures
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Public
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Templates
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Videos
Often the character is chosen to be mnemonic for its purpose, like choosing the letter l for long or r for reverse. By default the ls command prints the results in alphabetical order, so adding the -r option will print the results in reverse alphabetical order.
sysadmin@localhost:~$ ls -r
Videos  Templates  Public  Pictures  Music  Downloads  Documents  Desktop
Multiple options can be used at once, either given as separate options like -l -r or combined like -lr. The output of all of these examples would be the same:
ls -l -r
ls -rl
ls -lr
As explained above -l gives a long listing format while -r reverses the listing. The result of using both options is a long listing given in reverse order:
​⁠​‌‌⁠⁠⁠⁠​
sysadmin@localhost:~$ ls -l -r
total 32
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Videos
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Templates
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Public
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Pictures
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Music
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Downloads
drwxr-xr-x 4 sysadmin sysadmin 4096 Aug  4 20:58 Documents
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Desktop
sysadmin@localhost:~$ ls -rl
total 32
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Videos
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Templates
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Public
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Pictures
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Music
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Downloads
drwxr-xr-x 4 sysadmin sysadmin 4096 Aug  4 20:58 Documents
drwxr-xr-x 2 sysadmin sysadmin 4096 Aug  4 20:58 Desktop
Ultimately, commands can use many combinations of options and arguments, the possibilities for each command will be unique. Remember the aptitudeeaster egg?
sysadmin@localhost:~$ aptitude moo
There are no Easter Eggs in this program.
It is is possible to alter the behavior of this command using options. See what happens when the -v(verbose) option is added:
sysadmin@localhost:~$ aptitude -v moo
There really are no Easter Eggs in this program.
By combining multiple -v options, we can get a variety of responses:
sysadmin@localhost:~$ aptitude -vv moo
Didn't I already tell you that there are no Easter Eggs in this program?
sysadmin@localhost:~$ aptitude -vvv moo
Stop it!
Remember multiple options can be denoted separately or combined:
aptitude -v -v moo
aptitude -vv moo
Keep adding -v options to see how many unique responses you can get!

Comments