How to Create a Persistent Bash Alias in Ubuntu

In Linux, the command line is highly efficient because you can string multiple commands together. However, if there is a long, complex command you find yourself typing repeatedly—such as connecting to a specific remote server via SSH or updating system packages—typing it out manually every time is a waste of effort.

To solve this, Linux allows you to create an alias. An alias is a custom shortcut; you type a short, memorable word, and the system executes a long, complex command in the background. While you can create temporary aliases in the terminal, they disappear the moment you close the window.

In this guide, you will learn how to create a persistent bash alias in Ubuntu Linux so that your custom shortcuts are permanently available every time you open the terminal.

Step 1: Open Your .bashrc File

In Ubuntu (and most Linux distributions using the Bash shell), user-specific terminal configurations are stored in a hidden file located in your home directory called .bashrc.

To make an alias permanent, you must add it to the bottom of this file.

  1. Open your Ubuntu Terminal.
  2. Open the .bashrc file using the nano text editor. Ensure you are editing the file in your home directory by using the tilde (~) symbol:
    nano ~/.bashrc
  3. The nano editor will open within the terminal, displaying the configuration code. Do not delete or modify any of the existing text, as it controls how your terminal functions.

Step 2: Add Your Custom Alias

You should place your custom aliases at the very bottom of the document to keep them organised and separate from the system configurations.

  1. Use the Down Arrow key on your keyboard to scroll all the way to the bottom of the file.
  2. The syntax for creating an alias is incredibly strict. There must be no spaces around the equals sign. The format is:
    alias shortcutname='the full command goes here'
  3. For example, if you frequently run the system update command (sudo apt update && sudo apt upgrade -y) and want to shorten it to just update, type the following on a new line:
    alias update='sudo apt update && sudo apt upgrade -y'
  4. You can add as many aliases as you like, placing each one on a new line. For instance, to create a shortcut for navigating to a deeply buried web directory:
    alias web='cd /var/www/html/public_html/'

Step 3: Save and Exit the Editor

Once you have typed your custom aliases, you need to save the file and exit the nano editor.

  1. Press Ctrl + O (the letter O, not zero) to “Write Out” (save) the file.
  2. Nano will ask you to confirm the file name to write to (it should say .bashrc). Press Enter to confirm.
  3. Press Ctrl + X to exit the nano editor and return to the standard terminal prompt.

Step 4: Reload the Configuration

Even though you have saved the file, your new aliases will not work immediately. The terminal only reads the .bashrc file when it first launches.

You have two options to activate your new shortcuts:

  1. Close the terminal window completely and open a new one.
  2. Force the current terminal session to re-read the configuration file by using the source command:
    source ~/.bashrc

Your permanent aliases are now active. Type your custom shortcut word (e.g., update) and press Enter; Linux will seamlessly execute the full command.

Get the best tech tips delivered straight to your inbox.

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