Lesson 97: alias Command
In this lesson, you'll learn how to create, list, and remove command aliases to optimize your workflow in Linux.
Linux users frequently need to use one command over and over again. Repeatedly typing or copying and pasting the same command reduces your productivity and distracts you from what you are supposed to be doing.
To optimize your workflow and save valuable time, you can create aliases for the most commonly used commands.
Aliases are like custom shortcuts that represent a command (or set of commands) that can be executed with or without custom options.
Chances are, you are already using aliases on your Linux system without even knowing it.
alias Command Syntax
$ alias shortName="your custom command here"
alias Command Options
| Option | Description |
|---|---|
alias |
List all currently defined aliases |
alias name="command" |
Create a new alias |
unalias name |
Remove a specific alias |
unalias -a |
Remove all defined aliases |
1. List Currently Defined Aliases
You can see a list of defined aliases on your profile by simply executing the alias command:
$ alias
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias grep='grep --color=auto'
alias wr='cd /var/www/html'
alias home="ssh -i ~/.ssh/mykep.pem [email protected]"
The output will return a list of all the currently defined aliases for your user in the system, including any default aliases set up by the system or your shell configuration.
Let's execute the ls -alF and ll commands to compare their results and confirm whether ll is indeed an alias for the ls -alF command:
$ ll
$ ls -alF
total 64
drwxr-xr-x 8 tecmint tecmint 4096 Oct 1 18:30 ./
drwxr-xr-x 23 tecmint tecmint 4096 Oct 1 17:45 ../
-rw------- 1 tecmint tecmint 982 Oct 1 18:15 .bash_history
-rw-r--r-- 1 tecmint tecmint 220 Sep 29 10:00 .bash_logout
-rw-r--r-- 1 tecmint tecmint 3526 Sep 29 10:00 .bashrc
drwxr-xr-x 3 tecmint tecmint 4096 Oct 1 18:30 Documents/
drwxr-xr-x 2 tecmint tecmint 4096 Sep 30 14:20 Downloads/
You can create an alias with a single character that will be equivalent to a command of your choice.