Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to list down all the available commands and aliases on Linux?
Linux provides a vast collection of commands and aliases that users can utilize in the terminal. These commands serve different purposes and can be executed from anywhere in the command line interface. Understanding how to list available commands and aliases is essential for efficient Linux system administration and usage.
There are several approaches to discover all available commands in Linux. You can write custom shell scripts or use built-in shell functions designed for this purpose. The most effective method involves using the compgen command, which is a bash builtin specifically designed to list various shell components.
Using the compgen Command
The compgen command is a powerful bash builtin that can enumerate different types of shell components including commands, aliases, keywords, and built-ins.
Syntax
compgen -flag
The flag parameter accepts various options to specify what type of components to list:
-c − Lists all available commands
-a − Lists all defined aliases
-k − Lists all shell keywords
-b − Lists all shell built-ins
-A function − Lists all defined functions
-A function -abck − Lists everything above in one command
Listing All Available Commands
To list all commands, create a shell script file and execute the following steps:
touch list_commands.sh
Add the following content to the script:
#!/bin/bash compgen -c
Make the script executable and run it:
chmod +x list_commands.sh ./list_commands.sh
if then else elif fi case esac for select while until do done ls cat grep awk sed ...
Listing All Aliases
To display all defined aliases, modify your script content to:
#!/bin/bash compgen -a
You can also filter the output to find specific aliases:
compgen -a | grep ls
Alternative Methods
Besides compgen, you can use other commands to explore available tools:
| Command | Purpose | Example |
|---|---|---|
which |
Locate a command | which ls |
type |
Display command type | type ls |
alias |
Show all aliases | alias |
help |
List built-in commands | help |
Using the alias Command
alias
alias ll='ls -alF' alias la='ls -A' alias l='ls -CF'
Conclusion
The compgen command provides the most comprehensive way to list available Linux commands and aliases. Combined with other utilities like alias, which, and type, users can efficiently discover and explore the vast array of tools available in their Linux environment.
