Linux alias command: How to create and manage aliases easily

The Linux alias command lets you create shortcuts for longer or multiple commands, making your command line usage more efficient and user-friendly for executing complex commands more quickly.
In this guide, you’ll learn how to create temporary and permanent aliases in Linux and how to manage and remove them. You’ll also see practical examples you can start using right away.
What is a Linux alias?
A Linux alias is a bash alias command that replaces a longer command with a custom command to simplify command-line usage.
alias ll='ls -la'
When you run a command like ll, the shell interprets the alias and substitutes it with ls -la before executing it. This substitution happens at the shell level, so the alias never reaches the system as-is. Aliases are expanded early in the command evaluation process, before functions, built-in commands, and external commands.
This makes them a fast and convenient way to reduce repetitive typing and avoid mistakes in the terminal.
Linux alias command syntax and options
Linux alias syntax
The general form of the alias command is:
alias name='command'
Quoting the command is important, especially when it contains spaces or special characters. Without quotes, the shell can misinterpret parts of the command, like in this example:
alias ll=ls -la
This treats only ls as the alias value and tries to run -la as a separate command, which will fail. In this case, the correct syntax would be:
alias ll='ls -la'
This practice is essential in the shell configuration file to avoid errors. Note that aliases are case-sensitive, so ll and LL would be treated as different names.
Alias command options
The alias command itself has limited options, but here are the key ones:
- alias – List all defined aliases.
- alias name – Show the alias definition for a specific shortcut.
- alias name=’command’ – Create an alias.
- unalias name – Remove a specific alias.
- unalias -a – Remove all aliases in the current session.
These alias command options let you define, manage, or remove Linux aliases easily, whether you’re using a single alias or managing multiple options.
How to create an alias in Linux
Make a temporary alias (session-only)
A temporary alias in Linux exists only for the current terminal session and disappears once you close the terminal. In contrast, permanent aliases are saved in configuration files and automatically loaded when you start a new shell. Here’s how to create an alias in Linux using the following syntax:
- Write the alias. Define a shortcut using the alias command
alias diskspace='df -m'
- Run the alias. Use the alias just like a regular command to execute the intended task.
diskspace
- Test it. It should show the available and used disk space in MB. Close the terminal and try running diskspace again in a new terminal session to confirm whether it still exists.
Make a permanent alias
Add an alias to your shell configuration file to make it permanent across terminal sessions. After that, reload the file or restart the terminal to apply the change. Here’s where to place aliases based on your shell:
Shell | Configuration file | Reload command |
Bash | ~/.bashrc | source ~/.bashrc |
Zsh | ~/.zshrc | source ~/.zshrc |
Sh | ~/.profile | source ~/.profile |
You can add a new alias by appending it to the appropriate file. For example, use the echo command to append the alias definition:
echo "alias diskspace='df -m'" >> ~/.bashrc source ~/.bashrc
And in Zsh:
echo "alias diskspace='df -m'" >> ~/.zshrc source ~/.zshrc
Running source reloads the configuration file immediately without restarting the terminal. Alternatively, you can close and reopen the terminal to load the changes.
Storing aliases in a separate file allows you to better manage the Linux alias command across user environments. Per-user aliases go into your shell config files like .bashrc or .zshrc. If you want the alias available to all users, place it in a script under /etc/profile.d/.
Be careful when aliasing critical commands like rm, shutdown, or reboot in shared environments. Avoid creating aliases that obscure or alter the behavior of important system tools unless the intent is clearly communicated.
Warning! Files in /etc/profile.d/*.sh are executed for all users. Adding aliases here affects everyone on the system. Use caution and avoid adding anything user-specific or insecure.
How to list existing aliases
To view all currently defined aliases in your session, run:
alias
This will display all the aliases in the format alias name=’command’. For a script-friendly output, use:
alias -p
This is helpful if you’re exporting aliases or using them in scripts, since it outputs in a plain format without color or formatting that could interfere with parsing.
Many Linux distributions, like Ubuntu or Fedora, come with preconfigured aliases by default. These often include colored versions of commands like ls or grep to improve readability in the terminal.
How to remove an alias
Delete one alias with unalias name
To remove a specific alias from your current session, use the unalias command followed by the alias name:
unalias diskspace
Use the following command to verify whether the alias or a command with the same name exists:
type -a diskspace
If the alias is gone and no command with that name exists, type -a will return “not found.”
Delete all aliases with unalias -a
If you want to remove every alias currently defined in your session, use:
unalias -a
The unalias command removes all the defined aliases created using the alias command, including those loaded from the bashrc file. It does not delete permanent aliases. When you open a new terminal, those saved aliases will load again unless removed from the config file.
15 practical Linux alias examples
Here are useful aliases, each one a practical example, you can add to speed up your workflow:
Navigation
- alias ..=’cd ..’ – Move up one directory.
- alias …=’cd ../..’ – Move up two directories.
- alias home=’cd ~’ – Jump straight to your home directory.
Safety
- alias rm=’rm -i’ – Ask for confirmation before deleting files.
- alias cp=’cp -i’ – Ask before overwriting when copying.
- alias mv=’mv -i’ – Ask before overwriting when moving files.
Git
- alias gst=’git status’ – Show the current status of your Git repo.
- alias gaa=’git add .’ – Stage all changes.
- alias gcm=’git commit -m’ – Commit with a message.
- alias gp=’git push’ – Push changes to the remote repository.
Docker/Kubernetes
- alias dps=’docker ps’ – List running Docker containers.
- alias dcu=’docker-compose up’ – Start Docker Compose services.
- alias k=’kubectl’ – Shorten kubectl to k.
- alias kgp=’kubectl get pods’ – List Kubernetes pods.
System updates
- alias update=’sudo apt update && sudo apt upgrade’ – Update package lists and install available upgrades for Ubuntu and Debian-based systems.
Conclusion
Aliases are one of the simplest ways to improve Linux shell shortcuts and work faster. The shell expands the alias before executing the underlying command. As a result, you can create quick, customizable shortcuts that cut down on typing, help you avoid repeating the same command, and reduce mistakes.
Start by creating Linux aliases for commonly used commands in your Linux system to reduce repetition and streamline your terminal session. The more repetitive or complex the command, the more benefit you’ll get from turning it into a shortcut.
Remember, temporary aliases are great for quick fixes, but for anything you use regularly, add a permanent alias to your shell configuration file so it loads automatically in every session.
You’ve learned how to create aliases, make them permanent, remove them when needed, and apply them to tools like Git, Docker, and system navigation. Over time, you’ll build a cleaner, faster, and more efficient command line environment, saving valuable free time during daily operations.
Linux alias FAQ
Does alias work in Bash scripts?
Not by default. Bash scripts typically run in non-interactive shells, where alias expansion is disabled. You can enable alias expansion by adding shopt -s expand_aliases at the top of your script before any alias definitions. However, using aliases in scripts is generally discouraged. Shell functions are more robust and portable.
How do I bypass an alias?
To bypass an alias and run the original command, prefix it with a backslash. For example, if ls is aliased to ls –color=auto, running \ls will execute the real ls without the alias. This is useful when an alias interferes with specific command behavior you need.
Where are default Ubuntu aliases stored?
The default Ubuntu alias commands are usually defined in the /etc/bash.bashrc file for system-wide use and in each user’s bashrc file for personal settings. These files are executed when a new interactive shell starts. Use a text editor to review or change the alias definition in each file, or create new aliases for your custom commands.
All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.