List all the optional arguments of a particular command in bash
It's by no means universal, but many commands provide a usage summary in response to a -h
or --help
argument e.g.
$ cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.
With no FILE, or when FILE is -, read standard input.
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines
-s, --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version output version information and exit
Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/cat>
or available locally via: info '(coreutils) cat invocation'
The best approach depends on what kind of command you are running. You can try -h
or --help
as steeldriver suggests, though for some commands that may not show all available options. Ideally, all options would be shown; even then, though, they might not all be explained. Official documentation, such as a man
or info
page, will usually show and explain all options--or at least all of them that the developers expect users to actually use. (Undocumented options do sometimes exist.)
First I recommend checking whether the command is an external command or a shell builtin. You can do this with the type
command. In bash
, you can pass the -a
flag to the type
command, to show what would run if the first match didn't exist:
ek@Io:~$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
For me (and probably you), ls
is an alias. Alias expansion is nonrecursive, so the ls
in ls --color=auto
doesn't use the alias, but uses the second listing, /bin/ls
, instead. This is a path to an executable file, and thus an external command.
Therefore, to view documentation on ls
including all available options, I would run man ls
.
Some cases, like cat
, are simple:
ek@Io:~$ type -a cat
cat is /bin/cat
Commands that are built into the shell don't usually have their own manual pages, but you can use the help
builtin to learn about them:
ek@Io:~$ type -a history
history is a shell builtin
ek@Io:~$ type -a help
help is a shell builtin
Thus you can run help history
to learn about history
or help help
to learn about help
.
For some builtins, like compgen
, the help
builtin shows you all their options, but it doesn't explain most of them. Whenever you need more information about a shell builtin, you can consult the manual page for bash
(man bash
), or you can consult the longer and more complete documentation by running info bash
or visiting it online. You may find the section on builtins especially useful.
Some commands are available both as external executables and as shell builtins, which is another reason using type -a
first can be helpful:
ek@Io:~$ type -a printf
printf is a shell builtin
printf is /usr/bin/printf
If you run man printf
, for example, you will not be shown any information about the -v
option, because /usr/bin/printf
does not support it. The bash
shell builtin does, though, and the text shown when you run help printf
lists and explains it.
Finally, for manpages, it's useful to know that you can read them online.