compgen command in Linux with Examples

compgen is a bash built-in command which is used to list all the commands that could be executed in the Linux system. This command could also be used to count the total number of commands present in the terminal or even to look for a command with the specific keyword. This command is even used to print the bash details like bash builtin functions and stuff.

Working with compgen command in Linux

1. To list all commands available to be directly executed.

compgen -c

To-list-all-commands-available-to-be-directly-executed

This will list all the commands available to you for direct use.

2. To search for commands having a specific keyword



compgen -c | grep gnome

To-search-for-commands-having-a-specific-keyword

This will search the commands having the keyword gnome in them.

3. To count total number of commands available for use

compgen -c | wc -l

To-count-total-number-of-commands-available-for-use

This command will count the total number of commands that could be used.

4. To list all the bash alias

compgen -a

To-list-all-the-bash-alias

This command will list all the bash alias present in your system.



5. To list all the bash built-ins

compgen -b

To-list-all-the-bash-bulitins

This command will list all the bash built-ins present in your system.

6. To list all the bash keywords

compgen -k

6To-list-all-the-bash-keywords

This command will list all the bash keywords present in your system.

7. To list all the bash functions.

compgen -A function

7To-list-all-the-bash-functions

This command will list all the bash functions present in your system.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.