Aliases and shell functions turn frequently-typed long commands into short, memorable shortcuts — a small investment that saves real time across daily VPS administration.
Creating a Simple Alias
alias ll='ls -lah'
Typed directly, this alias only lasts for the current shell session — add it to a startup file to make it permanent.
Making Aliases Permanent
nano ~/.bashrc
alias ll='ls -lah'
alias update='sudo apt update && sudo apt upgrade -y'
alias dcup='docker compose up -d'
alias dclogs='docker compose logs -f'
source ~/.bashrc
Useful Aliases for Common VPS Tasks
alias diskspace='df -h'
alias meminfo='free -h'
alias ports='sudo ss -tulnp'
alias myip='curl ifconfig.me'
alias reload='sudo systemctl daemon-reload'
Creating a Shell Function for More Complex Shortcuts
mkcd() {
mkdir -p "$1" && cd "$1"
}
Unlike simple aliases, functions can accept arguments and include actual logic — here, creating and immediately entering a directory in one command.
A Function for Quick Backups Before Editing a Config File
backup() {
cp "$1" "$1.bak.$(date +%Y%m%d%H%M%S)"
echo "Backed up to $1.bak.$(date +%Y%m%d%H%M%S)"
}
backup /etc/nginx/nginx.conf
A Function to Quickly Find and Kill a Process by Name
killp() {
ps aux | grep "$1" | grep -v grep | awk '{print $2}' | xargs -r kill
}
Organizing Aliases in a Separate File (Cleaner Approach)
nano ~/.bash_aliases
# Add aliases here
nano ~/.bashrc
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Keeps your main .bashrc cleaner and makes aliases easier to manage/version-control separately.
Sharing Aliases Across a Team
Consider committing a shared .bash_aliases file to a team dotfiles repository, so common shortcuts are consistent across everyone's environment on shared or personal servers.
Viewing All Currently Defined Aliases
alias
Removing an Alias for the Current Session
unalias ll
Common Errors
Alias doesn't persist after reconnecting — verify it was added to ~/.bashrc (not just typed interactively) and that you're using bash (not a different shell like zsh, which uses different configuration files).
Continue Reading
- How to Manage Multiple SSH Sessions and Config Profiles
- How to Set Up systemd Timers as a Cron Alternative
- How to Transfer Files To and From a VPS (SCP, SFTP & rsync)
Browse more articles in Linux Server Administration.