Aliases in Linux are shortcuts for longer commands, enabling quicker and more efficient command-line navigation.
Whether you frequently type a complex command or want to customize your command-line experience, aliases are a powerful tool for any Linux user or administrator.
What are Aliases? #
In Linux, an alias is a custom shortcut for a command or set of commands.
By creating an alias, you can turn a lengthy or complex command into a shorter, more manageable one. Aliases are often used to create simplified commands, avoid repetitive typing, or even create safer command variations.
For example, the ls -alh
command (to list all files in a directory with details) can be shortened to ll
by creating an alias.
Why Use Aliases? #
- Increase Efficiency: Quickly run commands without typing the full syntax every time.
- Avoid Repetitive Typing: Commonly used commands are shortened to save time.
- Prevent Mistakes: Set up safer versions of potentially harmful commands, such as
rm
(remove). - Customize Your Environment: Personalize your command-line experience.
Creating Aliases #
Aliases can be temporary (for the current session) or permanent (available each time you open a terminal).
Temporary Aliases
- To create a temporary alias, use the following syntax in the terminal:
alias [alias_name]='command'
For example:
alias ll='ls -alh'
- In the above example, typing
ll
will executels -alh
. Temporary aliases will last only for the current terminal session.

Permanent Aliases
To make an alias permanent, add it to a shell configuration file like .bashrc
(for Bash users) or .zshrc
(for Zsh users). The file is usually found in the home directory of the user.
- Open your shell configuration file in a text editor:
vi ~/.bashrc
or
vi ~/.zshrc #for Zsh users
- Add your alias at the end of the file:
alias ll='ls -alh'

- Save and close the file.
- To activate the alias immediately, source the configuration file:
source ~/.bashrc
or
source ~/.zshrc #for Zsh users

Now, the alias will persist across terminal sessions.
In case you add an alias with wrong syntax, you will get an error when you run source ~/.bashrc to reload the configuration file.
Commonly Used Aliases #
- You literally set up alias for any commands that you mostly use.
- These could server login commands like ssh -p yourServerPost root@yourServer IP or any other commands that you run
- Below are some examples
Below are some examples
alias ll='ls -alh' # Long list with human-readable sizes
alias la='ls -A' # List all except . and ..
alias l='ls -CF' # List in columns, append / to directories
Navigation Shortcuts
alias ..='cd ..'
alias …='cd ../..'
alias ….='cd ../../..'
Safer Commands
alias rm='rm -i' # Prompt before deleting
alias cp='cp -i' # Prompt before overwriting files
alias mv='mv -i' # Prompt before moving files
Updating and Upgrading (for Debian/Ubuntu users)
alias update='sudo apt update && sudo apt upgrade -y'
System Information
alias meminfo='free -m -h' # Check memory usage in MB/GB
alias cpuinfo='lscpu' # Display CPU info
Removing Aliases #
To delete a temporary alias during the session:
unalias alias_name
For example:
unalias ll

To remove a permanent alias, delete it from your shell configuration file and reload the file:
- Open
~/.bashrc
or~/.zshrc
in a text editor. - Delete the alias line.
- Save and exit, then reload the file using the command below
source ~/.bashrc # or ~/.zshrc
Listing Aliases #
To view all current aliases:
alias

Or for a specific alias:
alias alias_name
Royal tip on creation of Aliases #
- Use Descriptive Names: Use short but meaningful names to remember your aliases easily.
- Be Careful with Overrides: Some aliases can override default commands; ensure this is intentional.
- Document Your Aliases: Keep a list of your aliases, especially if you share configurations across systems.
Author’s Final word #
Aliases in Linux are a great way to streamline command-line work and improve efficiency.
They allow customization, save time, and can even add an extra layer of safety for potentially destructive commands. Start by setting up a few helpful aliases, and as you grow more comfortable, explore advanced techniques to maximize productivity.