3

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"

  • 3
    Assuming your shell is bash then compgen -c will work. – fd0 Jun 30 '16 at 20:52
  • 1
    maybe it is because I am using zsh I am getting zsh: command not found: compgen – Your Friend Ken Jul 1 '16 at 15:28
  • yep, if I enter bash then compgen -c it works, I guess my question should have been what it the zsh equivalent to the bash command compgen -c – Your Friend Ken Jul 1 '16 at 15:33
  • so I think if you are using zsh and have tweaked your default shell on a Mac then you must already be quite an advanced user :) – forgotstackxpassword Jul 2 '16 at 10:49
  • I'm starring your question, because even though it was "is there a way to list..." it is always interesting to come back & see what other people are using the command line for on OSX – forgotstackxpassword Jul 2 '16 at 10:50
7

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.

4

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.

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...

0

While in Terminal, type Tab Tab. Then you'll see:

Display all 1653 possibilities? (y or n).

Press Y and it will list all possible commands

  • In my case, pressing tab inserts tab. So this probably depends on the Terminal being used. – trusktr Apr 29 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .