Every Linux user types the same commands over and over. ls -la to list files. cd into that one deep project folder. Update the system, then upgrade it. Each command is small — but together, they eat minutes from every single day.
The shell has two built-in tools that fix this: aliases for shortening commands, and functions for anything that needs logic. In this short guide, you'll learn both, when to use which, and how to make them permanent.
Aliases: Shortcut for Any Command
An alias is a simple text substitution. When you type the shortcut, the shell replaces it with the full command.
alias ll='ls -la' Now typing ll runs ls -la:
ll total 24K drwxr-xr-x 3 yeasin yeasin 4.0K Oct 17 12:00 projects -rw-r--r-- 1 yeasin yeasin 2.2K Oct 16 18:42 notes.txt A few that most people set up on day one:
alias ll='ls -la' alias gs='git status' alias up='sudo apt update && sudo apt upgrade -y' alias ..='cd ..' alias ports='ss -tlnp' Managing aliases
alias # list all current aliases type ll # see what a specific alias expands to unalias ll # remove one alias Aliases can include arguments at the end
An alias simply appends whatever you type after it:
alias gs='git status' gs --short # runs: git status --short Safety aliases
Aliases can also protect you from yourself:
alias cp='cp -i' # ask before overwriting alias mv='mv -i' alias rm='rm -i' # ask before deleting Warning: These safety aliases create a habit of trusting
rmto ask. But aliases only exist in interactive shells — inside scripts, on other servers, or as root, plainrmdeletes silently. Treat the safety alias as a convenience, not a guarantee.
Bash Functions: Aliases With Logic
Aliases have a hard limit: they are pure text replacement. The moment you need arguments in the middle of a command, or any logic at all, you need a function.
mkcd() { mkdir -p "$1" && cd "$1" || return } Usage:
mkcd projects/new-app This creates the directory (including parents) and enters it — one command instead of two. The "$1" is the function's first argument, quoted to survive spaces in names.
A few more genuinely useful examples:
# Extract any archive with one command extract() { case "$1" in *.tar.gz) tar -xzf "$1" ;; *.tar.xz) tar -xJf "$1" ;; *.zip) unzip "$1" ;; *) echo "Unknown archive type: $1" ;; esac } # Create a directory and cd into a project goto() { cd ~/projects/"$1" 2>/dev/null || echo "No project: $1" } # Quick backup of a file backup() { cp "$1" "$1.bak-$(date +%Y%m%d)" } Now backup notes.txt produces notes.txt.bak-20261017 — and arguments land exactly where you put $1, which is the thing aliases can never do.
Alias vs Function: Which One?
The rule is simple:
| Use | When |
|---|---|
| Alias | One command, fixed text, maybe arguments appended at the end |
| Function | Arguments in the middle, multiple steps, if/else logic, variables |
Quick test: if you can write it as shortcut='one command', it's an alias. The moment you need $1 somewhere inside the command, or more than one step, write a function.
Making Them Permanent
An alias or function typed in the terminal dies when the terminal closes. To keep them, put them in a shell startup file.
On Debian and Ubuntu, add them to ~/.bashrc:
nano ~/.bashrc Add your aliases and functions at the end of the file, save, then reload:
source ~/.bashrc source re-reads the file so your changes apply immediately — no new terminal needed.
Tip: As your collection grows, keep it organized in a separate file and load it from
~/.bashrcwith one line:# inside ~/.bashrc [ -f ~/.bash_aliases ] && source ~/.bash_aliasesMany systems include this line by default — check your
~/.bashrcfirst. A dedicated aliases file is easier to back up, share between machines, and read later.
Common Mistakes
1. Forgetting to reload — You added the alias to ~/.bashrc but it doesn't work. Run source ~/.bashrc or open a new terminal.
2. Confusing zsh and bash — If you use zsh (or a framework like Oh My Zsh), your config lives in ~/.zshrc, not ~/.bashrc. The syntax in this article works the same.
3. Naming an alias over a real command — alias ls='ls -la' changes ls everywhere, including inside your muscle memory from tutorials. Safer: pick a fresh name like alias l='ls -la', or check for collisions first with type name.
4. Too many aliases — If you forget what a shortcut does, it costs more time than it saves. Keep alias (with no arguments) handy to review your list, and prune anything you don't use.
Summary
- Aliases are text shortcuts — perfect for one fixed command with optional trailing arguments.
- Functions handle arguments anywhere, multiple steps, and logic like
if/else. - Rule of thumb: can't be one line with
$1in the middle? Write a function. - Make them permanent by adding them to
~/.bashrc(or~/.zshrc), thensourceit. - Safety aliases like
rm -iare conveniences, not guarantees — plain commands still work elsewhere.
Ten minutes of setup today saves you hours over a year — and building your own shortcut collection is one of the first steps where the shell starts feeling truly yours.
