Is there a way to list all available commands in terminal
Is there a way to list all available commands in terminal?
I know linux has compgen -c
is there an equivalent command for OS X?
Update:
The actual issue was that I was using zsh instead of bash. So from zsh, I could either just open bash
or run a bash command from zsh bash -c "compgen -c"
Solution 1:
In zsh
you need to enable the completion system. Please read through man zshcompsys
. To install the completion system enter the command
compinstall
and follow the directions. Check the fpath
variable
echo $fpath
in my situation I needed to declare the variable in my .zshrc
fpath=(/usr/local/share/zsh/5.0.7/functions)
This is the location of my zsh functions
. After the compinit
line in your .zshrc
add the following lines
autoload -Uz bashcompinit
bashcompinit
This is the completions entries in my .zshrc
#\\\_ COMPLETIONS _///#
zstyle :compinstall filename '/Users/fd0/.zshrc'
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
autoload -Uz compinit
compinit
autoload -Uz bashcompinit
bashcompinit
I can now enter the command compgen -c
and it behaves similar to bash
.
Solution 2:
Just tap the Tab key twice (TabTab). You'll be prompted if you want to see all possible commands. Tap y and you'll be presented with a list.
You can do that same thing for individual commands to see all options for that specific command.
Solution 3:
Like fd0 commented above, the best source for quickly listing most everything you can do in the Terminal, is by using the Bash builtin compgen.
Compgen
interfaces with the "completion" function in Bash, so it is intended to keep a list of most everything you can do in the shell. So it is interesting that technically compgen is listing commands, aliases, and functions, as well as a few other things like builtins, variables, groups, jobs and service names. My experience is that it will not list everthing, like applications typcially ran in the GUI, which I will mention below. You can use the open
command in OSX for quite a few things, for example.
compgen -c
executes the command in a subshell environment, and its output is used as the possible completions, which is probably what you want. If Bash if your shell, it will spew out similar information for all commands or a single command if you press Tab Tab.
It's also common in OSX that many programs can be executed from the shell, so many program names that you'll find in /Applications can also be called via a CLI from the shell. Similarly, many programs are (at least) at /Applications/Utilities, some interesting stuff is at /System/Library/CoreServices/Applications (as well as other things under the /System main directory...), and as well sometimes custom programs get put under the classic Unix locations like /usr/bin, usr/local/bin, /opt, and /sys/bin.
Often you can find other interesting things to type, probably also covered above, by typing help
or help [command or argument]
, with more information about most programs or builtins coming with info [command]
or man [command].
Apropos
is also quite interesting, which you may know already. These things will get most everything, I imagine there are other things one just needs, or should, hack around and discover...