Beginner · 6 min · practise every command in the built-in terminal

Aliases

Aliases let you create shortcuts for long commands.

Create an alias

alias ll='ls -la'
alias grep='grep --color=auto'
alias ..='cd ..'
alias ...='cd ../..'
alias cls='clear'
alias ports='ss -tlnp'
alias myip='curl -s https://api.ipify.org'

View all aliases

alias

Remove an alias

unalias ll

Make aliases permanent

Add to ~/.bashrc:

# My aliases
alias ll='ls -la'
alias grep='grep --color=auto'
alias ..='cd ..'
alias update='sudo apt-get update && sudo apt-get upgrade'

Then: source ~/.bashrc

Functions for complex aliases

For aliases with arguments, use functions:

# Find text in files
function search() {
    grep -r "$1" .
}

# Make dir and cd into it
function mkcd() {
    mkdir -p "$1" && cd "$1"
}

Practice tasks

  1. Create an alias 'll' that runs 'ls -la'
  2. Use your new alias ll
  3. Create a shortcut alias '..' for going up one directory
  4. Remove the ll alias

Commands in this lesson

Shell & Environment