Open In App

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

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

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

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

4. To list all the bash alias

compgen -a

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

5. To list all the bash built-ins

compgen -b

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

6. To list all the bash keywords

compgen -k

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

7. To list all the bash functions.

compgen -A function

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

Article Tags :