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?
7 Answers
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'
- 5,178
- 87,451
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.
-
-
1Even the commands for gui-based programs are included. So if you do
compgen -c | grep thunarand you have the Thunar file manager installed, you'll see commands related to Thunar as well. – Jan 10 '14 at 14:00 -
1
-
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
-
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
-
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
- 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
Open up a terminal and press the Tab key twice.
- 641
- 6,806
-
2
-
@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
-
3Default != 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
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:
- Press Tab twice.
Use
findto find all executables:find / -perm +xList all the files in the binaries directories (could be incomplete):
ls /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin
- 69,302
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 NAMEto search for a command (or part of it) andman COMMANDto 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 | moreto know all exential administrative executables;ls /sbin | morefor common administrative executables.Use
ls /usr/sbin | moreto know all user executables;ls /usr/sbin | morewill give a very huge list of user executables and libraries.
NOTE: If the output frommoreexceeds one page (screenful), you'll have to scroll py pressing "Page Up" and "Page Down" or spacebar.
You can useCOMMAND | grep TEXTto 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.
- 3,175
-
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 asusermodandifconfig. And many systems have other binary directories as well, like/usr/gamesand/usr/local/bin. See Filesystem hierarchy standard andman 7 hier. You might want to expand this to mention important directories for executables besides/binand/usr/sbin. – Eliah Kagan Mar 10 '14 at 17:27
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.
- 1
bashbut not inzsh, 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