Last Updated : 09 Oct, 2024
The compgen command is a Bash built-in utility used to list all available commands that can be executed in a Linux system. It is a powerful tool for searching for commands based on specific keywords, counting the total number of commands, and printing Bash details such as built-in functions, keywords, and aliases. This article explores the various uses of the compgen command in Linux, along with examples.
Syntaxcompgen [option]
The command is typically used with various options to filter and display specific types of commands or Bash elements.
Common Use Cases and Options for the compgen Command 1. List All Available CommandsTo 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 keywordTo search for commands containing a specific keyword, you can combine the compgen command with grep. For example, to search for commands containing the keyword "gnome".
compgen -c | grep gnome
This will search the commands having the keyword gnome in them.
3. To count total number of commands available for useTo count the total number of commands available in the system, pipe the output of compgen -c to wc - l
compgen -c | wc -l
This command will count the total number of commands that could be used.
4. To list all the bash aliasTo list all the Bash aliases present in your system, use the -a option
compgen -a
This command will list all the bash alias present in your system.
5. To list all the bash built-insList all Bash built-in commands, use the -b option
compgen -b
This command will list all the bash built-ins present in your system.
6. To list all the bash keywordsList all Bash keywords available in the system, use the -k option
compgen -k
This command will list all the bash keywords present in your system.
7. To list all the bash functionsList all Bash functions present in your system, use the -A function option
compgen -A function
This command will list all the bash functions present in your system.
ConclusionThe compgen command is a versatile and useful tool in Bash for listing and searching various commands, aliases, built-ins, keywords, and functions in the Linux system. With the ability to filter and count commands, it can assist in better understanding and utilizing your command-line environment.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4