LinuxTutorial2 min read

How to Use Bash Aliases to Save Time on Linux

Create permanent Bash aliases in .bashrc to replace long commands with short ones — with real examples that will speed up your daily Linux workflow immediately.

Developer terminal on a laptop in low light

What Are Bash Aliases?

A Bash alias is a shortcut you define so that typing a short command runs a longer one. Instead of typing ls -lah --color=auto every time, you can type ll. Aliases are defined in your ~/.bashrc file, so they are available in every new terminal session.

Creating a Temporary Alias

Run this in your terminal for an alias that lasts until you close the session:

alias ll='ls -lah --color=auto'

Making Aliases Permanent

Open your .bashrc file:

nano ~/.bashrc

Add your aliases at the bottom, then save. Apply them to the current session:

source ~/.bashrc    # or: . ~/.bashrc

Practical Aliases to Add Right Now

# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ~='cd ~'

# Better ls
alias ll='ls -lah --color=auto'
alias la='ls -A'
alias l='ls -CF'

# Safety nets
alias rm='rm -i'          # ask before deleting
alias cp='cp -i'          # ask before overwriting
alias mv='mv -i'

# Git shortcuts
alias gs='git status'
alias ga='git add .'
alias gc='git commit -m'
alias gp='git push'
alias gl='git log --oneline --graph --decorate -10'

# System
alias update='sudo apt update && sudo apt upgrade -y'
alias please='sudo'
alias df='df -h'
alias du='du -sh'
alias free='free -h'
alias ports='ss -tulnp'

# Quick edit config
alias bashrc='nano ~/.bashrc'
alias reload='source ~/.bashrc'

Aliases with Arguments: Use Functions Instead

Aliases can't accept arguments. For that, define a Bash function in .bashrc:

# Create a directory and immediately cd into it
mkcd() { mkdir -p "$1" && cd "$1"; }

# Extract almost any archive
extract() {
  case "$1" in
    *.tar.gz)  tar xzf "$1" ;;
    *.tar.bz2) tar xjf "$1" ;;
    *.zip)     unzip "$1" ;;
    *.gz)      gunzip "$1" ;;
    *)         echo "Unknown archive format" ;;
  esac
}

List All Current Aliases

alias             # list all defined aliases
alias ll          # show a specific alias

Remove an Alias

unalias ll        # remove for the current session

To remove permanently, delete or comment out the line in ~/.bashrc.