Linux

Speed Up Your Terminal Workflow: A Complete Guide to Bash Aliases

This guide thoroughly explains what Bash aliases are, why they're needed, and how to properly configure them to speed up daily work in the Linux terminal. You'll learn to create, save, and use your own shortcuts for long commands.

Updated at February 16, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Linux (Ubuntu, Debian, CentOS, Fedora)Bash 4.0+

Introduction / Why This Is Useful

Bash aliases are your personal shortcuts for frequently used commands. Instead of typing a long command like git status --short --branch every time, you can create an alias alias gst='git status --short --branch' and use just two characters.

This guide will help you:

  • Save time on routine operations.
  • Reduce typos in complex commands.
  • Personalize your terminal to suit your needs.
  • Automate sequences of actions.

After completing this guide, you will have a more efficient and convenient workflow in the Linux command line.

Requirements / Preparation

Before you begin, ensure you have:

  1. Access to a Linux terminal (Ubuntu, Debian, Fedora, CentOS, etc.).
  2. Basic understanding of command line operation (how to run commands, navigate the file system).
  3. Any text editor (nano, vim, code, etc.). This guide uses nano as the simplest for beginners.
  4. Write permissions in your home directory (/home/your_user/), which are granted by default.

Step 1: Check Existing Aliases

First, let's see which aliases are already defined in your system. Open your terminal and enter:

alias

You will see a list, for example:

alias ls='ls --color=auto'
alias ll='ls -la --color=auto'
alias grep='grep --color=auto'
...

These are standard aliases that may be set by your distribution. They show the format, but we need to create our own.

Step 2: Identify and Prepare the Configuration File

Aliases that should work permanently are stored in special files that Bash reads on startup. Most commonly, these are:

  • ~/.bashrc — the main configuration file for interactive shells.
  • ~/.bash_aliases — a separate file, convenient to use only for aliases. It is imported from ~/.bashrc by default in many distributions.

Let's check if you have ~/.bash_aliases:

ls -la ~/.bash_aliases

If the file exists, use it. If not — create it or work with ~/.bashrc. Using ~/.bash_aliases is recommended for cleaner configuration.

Create the file if it doesn't exist (this is optional but convenient):

touch ~/.bash_aliases

Step 3: Open the File in a Text Editor

Let's open the chosen file (in the example ~/.bash_aliases) in the nano editor:

nano ~/.bash_aliases

If you decided to use ~/.bashrc, the command would be nano ~/.bashrc.

You will enter a simple text editor. To save and exit, press Ctrl+X, then Y (Yes), and Enter.

Step 4: Add Your Aliases

Now let's add some useful aliases. Each alias is a separate line of the form:

alias alias_name='command_with_arguments'

Examples to paste into the file:

# Safe package management (Ubuntu/Debian)
alias update='sudo apt update'
alias upgrade='sudo apt upgrade -y'
alias install='sudo apt install'

# Convenient file viewing
alias ll='ls -la --color=auto'
alias la='ls -A --color=auto'
alias l='ls -CF --color=auto'

# Git in two characters
alias g='git'
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gd='git diff'
alias gl='git log --oneline --graph --decorate --all'

# Quick navigation
alias ..='cd ..'
alias ...='cd ../..'
alias c='clear'

# Search with highlighting
alias h='history | grep'

💡 Tip: Add comments (lines starting with #) to explain what each block of aliases does. This will help in the future.

Important: If your command contains apostrophes ('), use double quotes (") for wrapping or escape the internal apostrophes with a backslash (\'). For example:

alias greet="echo 'Hello, world!'"

Step 5: Apply the Changes

After saving the file (Ctrl+X, Y, Enter in nano), the changes will not take effect in the currently open terminal. You need to "reload" the configuration. There are two ways:

  1. Run the source command (recommended):
    source ~/.bashrc
    

    or, if you edited ~/.bash_aliases:
    source ~/.bash_aliases
    
  2. Simply close and open a new terminal. The new session will automatically read the configuration files.

Now your aliases are ready to use! Try typing ll or gs.

Verifying the Result

Ensure the aliases work:

  1. Run alias | grep <your_alias_name>. For example:
    alias | grep ll
    

    It should output the line defining the alias.
  2. Simply type one of the new aliases in the terminal, for example update or .., and check if the corresponding command executes.
  3. Open a new terminal window and try the alias there. This guarantees the setting is permanent.

Potential Issues

  • "Alias not found" after reboot.
    • Cause: You added the alias to the file but forgot to save it, or you edited the wrong file (~/.bashrc instead of ~/.bash_aliases), and ~/.bashrc does not contain the line if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases; fi.
    • Solution: Ensure the line is saved. Check if your ~/.bashrc mentions ~/.bash_aliases. If not — add this line to the end of your ~/.bashrc:
      if [ -f ~/.bash_aliases ]; then
          . ~/.bash_aliases
      fi
      
      and run source ~/.bashrc again.
  • Alias works incorrectly, especially with arguments.
    • Cause: Incorrect syntax or using the alias in a script where it doesn't expand (aliases do not work in non-interactive scripts by default).
    • Solution: For aliases with parameters, check the order of $1, $2. For use in scripts, it's better to create functions in ~/.bashrc:
      mkcd() {
          mkdir -p "$1" && cd "$1"
      }
      
      Or use scripts in ~/bin/.
  • Alias name conflict with an existing command.
    • Cause: You gave the alias a name that is already a real command (e.g., alias ls='...'). This can break expected behavior.
    • Solution: Choose unique names. If you need to temporarily disable an alias and use the original command, use a backslash: \ls (instead of ls).
  • Alias does not work within a sudo command.
    • Cause: Aliases are expanded only for the current user. When using sudo, the command runs as root, who has their own set of aliases.
    • Solution: Either don't use an alias with sudo (call sudo inside the alias, as in the update example), or configure aliases for root (not recommended). The best option is alias update='sudo apt update'.
  • Syntax error when editing the file.
    • Cause: Extra spaces, missing quotes, or incorrect characters.
    • Solution: Check each line. Remember that after alias there must be a space, then the name, an = sign, and the command in quotes. Example of correct syntax: alias ll='ls -la'.

F.A.Q.

How to make an alias work in all terminal sessions?
Can I create an alias with parameters, for example, for a command with an argument?
Why doesn't my alias work after a reboot?
How to temporarily disable an alias without removing it from the config?

Hints

Check existing aliases
Identify configuration file
Open the file in a text editor
Add your aliases
Apply changes
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community