Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of all available shell commands

Tags:

bash

shell

In a typical Linux shell (bash) it is possible to to hit tab twice, to get a list of all available shell commands.

Is there a command which has the same behaviour? I want to pipe it into grep and search it.

like image 475
Dave Halter Avatar asked Mar 31 '12 23:03

Dave Halter


People also ask

How do you find all available shells in your system?

Explanation: The list of all the shells which are currently installed in our Linux system is stored in the 'shells' file which is present in /etc folder of the system. It has read-only access by default and is modified automatically whenever we install a new shell in our system.

How can I see all available commands in Linux?

At the command line, type compgen -c | more to list every command you can run. Use the space bar each time you'd like to go down another long page of text. You'll notice that this utility has an extremely broad idea of what a command is.


4 Answers

You could use compgen. For example:

compgen -c

You also could grep it, like this:

compgen -c | grep top$

Source: http://www.cyberciti.biz/open-source/command-line-hacks/compgen-linux-command/

like image 105
msbrogli Avatar answered Sep 23 '22 17:09

msbrogli


You can list the directories straight from $PATH if you tweak the field separator first. The parens limit the effect to the one command, so use: (...) | grep ...

(IFS=': '; ls -1 $PATH)
like image 34
DigitalRoss Avatar answered Sep 23 '22 17:09

DigitalRoss


"tab" twice & "y" prints all files in the paths of $PATH. So just printing all files in PATH is sufficient.

Just type this in the shell:

 # printf "%s\n" ${PATH//:/\/* } > my_commands

This redirect all the commands to a file "my_commands".

like image 36
P.P Avatar answered Sep 22 '22 17:09

P.P


List all the files in your PATH variable (ls all the directories in the PATH). The default user and system commands will be in /bin and /sbin respectively but on installing some software we will add them to some directory and link it using PATH variable.

like image 28
ganesshkumar Avatar answered Sep 26 '22 17:09

ganesshkumar