How to get a list of all the commands available for Ubuntu?

I want to start using the terminal more often, but I don't know what are the different commands available to me. Is there a way to list all the different commands that I can make use of?


Solution 1:

First Method

NB: Thanks to @Rmano. This method doesn't work with zsh shell.

A simple command:

ls ${PATH//:/ }

This will list all commands in your $PATH environment variable.

To store the result in a file you can redirect the output to a file.

ls ${PATH//:/ } > mycommands.txt

Note that this will return an error if any directory names in your $PATH contain spaces. In that case, use this instead:

while read -d ':' dir; do echo "$dir"; done <<<$PATH

Second Method

Also you can use:

compgen -c | sort -u > commands && less commands

Third Method

Another method is a double Tab click.

Fourth Method

Another method using find command:

find {,/usr}/{,s}bin -printf '%f\n\0'

Solution 2:

If you are using bash, which is the default shell in all official Ubuntu flavors, run compgen -c to see the available commands including aliases.

Solution 3:

Open terminal Ctrl + Alt + t and run this command:

whatis `compgen -c` | more 

This will list all commands and a simple description of each command.

If you want to save the list you can redirect the result into an output file

whatis `compgen -c` > listOfCommands.txt

So why I used whatis command. The command man whatis gives:

Each manual page has a short description available within it.
whatis searches the manual page names and displays the manual page descrip‐ tions of any name matched.

so in easy words whatis give a general. description of each command

Solution 4:

Open up a terminal and press the Tab key twice.

Solution 5:

A list of command depends greatly on what you have installed, but there are cheats to list all commands. The following works on most bourne-like shells:

  1. Press Tab twice.
  2. Use find to find all executables:

    find / -perm +x
    
  3. List all the files in the binaries directories (could be incomplete):

    ls /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin