How to Use the alias Command in Linux to Create Custom Terminal Shortcuts

If you spend a lot of time in the Linux terminal, you likely type the same long, complex commands repeatedly. Whether it is an intricate find command with multiple flags, a 15-character SSH login string, or a specific package manager update sequence, retyping these strings is both tedious and error-prone. To solve this, the Linux shell provides the alias command, allowing you to create custom, personalized keyboard shortcuts that execute long command strings instantly.

Why Use the alias Command?

The alias command acts as a text-replacement tool for the shell. When you type an alias and press enter, the shell intercepts your custom word, replaces it with the underlying long command, and executes it. This drastically speeds up your workflow. It is incredibly useful for shortening commands you use dozens of times a day, or for creating easily memorable names for obscure, syntax-heavy commands you only use occasionally.

Step 1: Create a Temporary Alias

You can create an alias instantly in your current terminal session. Note that an alias created this way will disappear as soon as you close the terminal window.

  1. Open your Linux terminal.
  2. Use the syntax alias name='command'. For example, to create a shortcut named update that runs the full Debian package update process:
alias update='sudo apt update && sudo apt upgrade -y'
  1. Press Enter.
  2. Now, type update and press Enter. The shell will execute the full apt update sequence.

Step 2: View Active Aliases

If you forget what aliases are currently active, you can list them.

  1. Simply type the command without any arguments:
alias

This will print a list of every active shortcut, including default aliases created by your Linux distribution (such as alias ls='ls --color=auto').

Step 3: Remove an Alias

If you made a mistake or want to delete a temporary shortcut, use the unalias command.

  1. Type the following command:
unalias update

Step 4: Create Permanent Custom Shortcuts

To ensure your custom shortcuts survive a reboot and are available every time you open a terminal, you must save them to your user’s shell configuration file (usually .bashrc or .zshrc).

  1. Open your bash configuration file in a text editor like nano:
nano ~/.bashrc
  1. Scroll to the very bottom of the file.
  2. Add your custom alias on a new line. For example:
alias logs='tail -f /var/log/syslog'
  1. Save the file (Ctrl+O, Enter) and exit nano (Ctrl+X).
  2. To apply the changes immediately without restarting the terminal, run the source command:
source ~/.bashrc

By defining a robust list of permanent aliases in your .bashrc file, you can heavily customize your Linux environment to match your personal workflow.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.