Open In App

compgen command in Linux with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

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.


Last Updated : 22 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads