Mac’s command line interface, Terminal, ships with a bewildering array of commands. Google searches and man pages will help you get a better sense of what your machine is capable of, but they won’t tell you the name of every command on your Mac. If you want to see all available commands at once, or if you’re trying to find a particular command, you can follow the instructions below to find out all the Terminal commands on your Mac.
Viewing All Available Terminal Commands
1. Open Terminal (Applications/Utilities/Terminal.app).
2. Hold down the “Escape” key (or button on a MacBook Pro Touchbar) for a second or two.
3. When you see the prompt that says “Display all 1456 possibilities?” press the “Y” key. Note that the exact number of available commands will vary based on your installation, but it should be approximately 1400.
4. Terminal will now list all of the available commands in alphabetical order. You can navigate down the list line by line by pressing the “Enter” key. There’s no way to navigate backwards, so read slowly.
5. To return to the command prompt, press “Control + C” or the “Delete” key to exit the list of available commands. You can also continue pressing the “Enter” key until you’ve scrolled through all the commands, at which point you’ll be automatically returned to the command prompt.
Generating a List of Commands with Compgen
What if you don’t want to see a list of commands in the terminal window, but you want to produce a text file containing all of the available Terminal commands? You can use compgen
to generate a list of all available commands and then send the result of the command to a new text file. You can also use grep
to search compgen’s output quickly.
1. Open Terminal (Applications/Utilities/Terminal.app).
2. To list all available Terminal commands (and command aliases) instantaneously, type in compgen -ac
and press “Enter.”
3. If you’d rather create a text file containing a list of all those commands, type the following command and press Enter:
compgen -ac > commandlist.txt
This will send the compgen
command’s output to a new text file named “commandlist.txt.” That file will then appear in your current working directory (your home directory, by default).
More Compgen Options
1. Use compgen -b
to display only built-in commands. These are the commands that are “built-in” to Bash, macOS’s default command line interpreter, like cd
and kill
.
2. Search compgen’s output using grep
, which is another terminal command search for text strings. For example, to find every command with “net” in the name, type the following command and press Enter:
compgen -ac | grep net
This will display a short list of all the commands with “net” in the title.
3. Use compgen -k
to list all available “keywords.” These keywords are commands that you can use when writing command line scripts for bash to execute.
Conclusion
To manually search through a list of all available Terminal commands, use the Escape key trick. This isn’t the best way to find a particular command, however. For a searchable and exportable directory of available commands, use compgen
along with one of its several command options.
Our latest tutorials delivered straight to your inbox