29

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?

Aditya
  • 13,626

7 Answers7

31

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'
Maythux
  • 87,451
  • Notice that the first command works in bash but not in zsh, which has word split disabled by default. http://www.refining-linux.org/archives/38/ZSH-Gem-3-No-automatic-word-split/ – Rmano Mar 10 '14 at 22:54
12

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.

  • Is that bash only? – Braiam Jan 10 '14 at 13:52
  • 1
    Even the commands for gui-based programs are included. So if you do compgen -c | grep thunar and you have the Thunar file manager installed, you'll see commands related to Thunar as well. –  Jan 10 '14 at 14:00
  • 1
    Mmm... is doesn't work in Debian. Which package provides that? – Braiam Jan 10 '14 at 14:03
  • works on Ubuntu server @Braiam Oh and it is a bash builtin. see: http://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion-Builtins – Rinzwind Jan 10 '14 at 14:08
  • 2
    @Rinzwind that explains it, I'm using zsh. – Braiam Jan 10 '14 at 14:10
  • 1
    @vasa1: Could this answer be more general? I mean it only provides the solution for bash, but as Braiam noted it doesn't work for zsh... If possible could you please expand the answer to cater to a larger audience - obviously only if you know the answer :-) – Aditya Jan 29 '14 at 10:37
  • @Aditya, no, I don't know about other shells. Bash, I understand, is the default shell in all official Ubuntu flavors. –  Jan 29 '14 at 11:43
  • -1 because this is not standard: it's a bash built-in and may not function with other common shells nor be usable with other bash forks. I suggest to enhance your post with the syntax for a bash alias. – Lorenzo Ancora Mar 10 '14 at 22:03
  • @lorenzo if Ubuntu + bash is OUR standard this answer is perfectly valid. – Rinzwind Mar 19 '14 at 11:08
  • @Rinzwind the "Ubuntu + bash" combination isn't a common standard and we can't (yet :) ) make our international standards; not all Ubuntu & Debian based systems must use any particular version of bash or of the bash scripting language: they can use dash, the korn shell etc. as default user shell. Also, remember that bash will not respect the POSIX standard by default and, for that, it is a replaceable interface to the system. The bash builtins - sadly - are not part of any standard, as I told: http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29#Portability Have a nice day. – Lorenzo Ancora Mar 19 '14 at 14:29
  • Why are you fighting? For zsh, it's just bash -c -- "compgen -c" – Thomas W. Jan 28 '16 at 15:21
5

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

Maythux
  • 87,451
  • 1
    +1 for additional info. whatis `compgen -c` | sort > listOfCommands.txt will help go get in sort list. – Saurav Kumar Mar 25 '14 at 07:44
  • Another useful command: apropos <keyword> searches all commands and their short description and displays the results – Aloso Dec 19 '17 at 16:17
3

Open up a terminal and press the Tab key twice.

dadexix86
  • 6,806
  • 2
    -1 because this is not standard. – Lorenzo Ancora Mar 10 '14 at 14:25
  • @LorenzoAncora why is it not standard? Does not all Ubuntu have the autocompletion with double Tab as standard behaviour? – dadexix86 Mar 10 '14 at 15:29
  • 3
    Default != standard: in a future maybe we'll have a console that does not support that mechanism, because it's not standard; more, the TAB standard may serve a different function. A standard procedure is listing the content of 'bin', because is part of the official FHS standard and any Linux/Unix system has that directory. The correct functionality (and the ability of the community to help the users) of Ubuntu is ensured by the respect of the standards. – Lorenzo Ancora Mar 10 '14 at 16:13
  • Ok, thanks for the explanation :) I thought that the standard behaviout of the double Tab on Ubuntu was to list the content of PATH :) – dadexix86 Mar 10 '14 at 16:22
  • @LorenzoAncora Listing the contents of any one directory will not show anywhere close to all executable commands. Listing the contents of all PATH directories will not show shell builtins with no corresponding executable (such as cd). Pressing Tab twice overcomes both these severe limitations. If someone had asked how to show all commands on an arbitrary GNU/Linux system, one might argue that Tab completion is not an adequate solution. Of course anything might change in Ubuntu in the future but the likelihood of tab completion in the default interactive shell going away is minuscule. – Eliah Kagan Mar 10 '14 at 17:30
  • For Eliah Kagan: Learning the build-ins (which are reduced versions of external utility) is part of knowing the shell, use the internal help for that. For dadexix: Enviroment variables, like PATH, can be altered and the listing of their content may vary from shell to shell, it's not a standard like the filesystem hierarchy. The default shell may vary. For both: I'm not here for useless philosophical disputes: in my opinion, if you don't know what shell the user is going to use, give a well documented and safe answer. Who knows the future? :-) – Lorenzo Ancora Mar 10 '14 at 20:44
2

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
    
Braiam
  • 69,302
1

Open a terminal window (GNOME terminal is OK, also a configured xTerm).
Your options are:

  • By pressing the TAB key ("-><-") twice, you'll complete any command in the console and, if the line is empty, you'll get the number and the names of all available commands. Please note that it may require some time and may list semi-administrative utilities. NOTE: this isn't a standard, for a "cross-shell" way see the other options.

  • Use man -k NAME to search for a command (or part of it) and man COMMAND to obtain the manual for that command. Not al commands have a system manual; reading the man before using any administrative utility is always a good idea; trust me.

  • Use Midnight Commander (mc) to have a nice console (curses) GUI to manage the system and the file system. You may have to install it from your package manager. Don't worry; it is safe and extremely common software.
    NOTE: It's made for when you have confusion or difficulty in using the file system.

  • Use ls /bin | more to know all exential administrative executables; ls /sbin | more for common administrative executables.

  • Use ls /usr/sbin | more to know all user executables; ls /usr/sbin | more will give a very huge list of user executables and libraries.
    NOTE: If the output from more exceeds one page (screenful), you'll have to scroll py pressing "Page Up" and "Page Down" or spacebar.
    You can use COMMAND | grep TEXT to filter the output.

If you have more questions comment under here and don't forget to check the tick next to the answer if I helped you.
Have a nice experience.

  • Usually, most executables are in /usr/bin, which you haven't mentioned here. Also there's /sbin, which contains executables often used for system administration, such as usermod and ifconfig. And many systems have other binary directories as well, like /usr/games and /usr/local/bin. See Filesystem hierarchy standard and man 7 hier. You might want to expand this to mention important directories for executables besides /bin and /usr/sbin. – Eliah Kagan Mar 10 '14 at 17:27
-1

This is a bit old, but can be still relevant

http://fosswire.com/post/2008/04/ubuntu-cheat-sheet/

And information on using the Ubuntu terminal

https://help.ubuntu.com/community/UsingTheTerminal

the above page has more links at the end which will help you finding more commands for Ubuntu.

Ednan
  • 1