Aliases and You

In case you haven’t encountered one before, an alias is just a nickname for a longer command. Whenever you invoke an alias by typing its name in your shell, Bash (or Zsh) simply substitutes the alias text before execution. That’s it.

It’s like the old joke:

Two old friends have been telling each other the same old jokes for decades. Eventually they tire of the long setups and just number the jokes.

While sitting on the porch, talking, one friend exclaims, “37”. The other friend howls with laughter: “Oh, that’s a classic!”

Later a newcomer hears about the system and wants to join in. He pipes up nervously: “42”

The room falls silent. Finally one of the old friends shrugs and says, “Well… it’s all in how you tell it”

That’s pretty much how an alias works

🙃 My aliases

Here are some aliases I’ve found useful—hopefully you’ll find a few that earn a spot in your own shell too. If you do want to try these out you can do so by entering them directly into your shell. After that you can invoke the alias by name for as long as the shell session lasts. If you want them to always be available, you can add them to your startup files (e.g., .bashrc or .zshrc) and reload. If you decide you don’t like an alias, you can always run unalias followed by the alias name (not including the = sign or the text to the right of it)

Overriding built-in commands.

The first batch overrides built-in commands. So you can type ll and it will be substituted for ls -LF --color=auto.

alias vi='vim'
alias l='ls -CF --color=auto'
alias ll='ls -LF --color=auto'
alias lf='find . -type f ! -path "*/.git/*" ! -path "*/venv/*"'

With those aliases set, you can simply type lf or ll instead of trying to remember the full command. These overriden commands can be really handy, especially on destructive commands like rm which have safety flags, like:

alias rm='rm -i'

Process aliases

These make some really powerful, but let’s face it, un-memorable ps commands trivial to use

alias ptop='ps aux --sort=-%mem | head -n 20'
alias pmem='ps aux --sort=-%mem | head -n 20 | awk '\''{print $1, $4, $11}'\'' | column -t'
alias pscpu='ps aux --sort=-%cpu | head -n 20 | awk '\''{print $1, $3, $11}'\'' | column -t'
alias pfor='ps auxf --forest'
alias psme='ps -u $(whoami) -o pid,etime,cmd --sort=-etime | head'

Launch Jupyter Notebook Server

This will launch jupyter without trying to open a browser tab and instead display the address to connect to and the auth token

alias jupyter-notebook="/usr/local/bin/jupyter-notebook --no-browser"

a purple wizard

Python virtualenv

The following aliases make it really easy to work with Python tools that require a virtual envirornment. venv will drop a venv folder in the current directory. va and vd activate and deactivate your venv automatically.

alias venv='python3 -m venv venv'
alias va='source venv/bin/activate'
alias vd='deactivate'

Git

Once upon a time I would have scoffed at the following since some of them like ga for git add seem pathetically simple. Try typing git add for the thousandth time and you too will appreciate a two letter alias that you can run with something like ga . or glo or gc -m "The next big thing"

alias gs='git status'
alias glo='git log --oneline --graph --decorate --all'
alias ga='git add'
alias gc='git commit'
alias gd='git diff'
alias gco='git checkout'
alias gp='git push'
alias gl='git pull'
alias gitcha='gcheck' # an alias i'm used to for the gcheck function

The gitcha alias is one where I had a simple git status && git remote alias that I used all the time until I built a way better function called gcheck. I made the alias so I can type what I’m used to and run the new code. With that I can either invoke my gcheck function or call that same function with the command gitcha. Nice.

Docker

Docker supports some format options that make the output way more readable but the commands are tricky to remember. Instead of copy/paste, you can make an alias. It’s easier to remember and thus you are more likely to use it once you get used to typing the simple alias.

alias docker_ps='docker ps --format "table {{.Names}}\t{{.Image}}"'
alias docker_net='docker ps --format "table {{.Names}}\t{{.Ports}}"'
alias docker_images='docker images --format "table {{.Repository}}\t{{.Size}}"'

Roll your own CLI trash can.

This is handy but you also need to manualy clear the trash folder you create or write a cron or systemd job to do it on a schedule.

alias rm='mv -t ~/.trash'

aliases can call each other

The only rule is that the one being called should be defined before the caller.

alias | grep git
alias aliasg='alias | grep'


### Misc tools

These two are great if you find yourself working with conf files for things like Apache and sshd that include tons of commented optional values. It can be helpful to see just the non-comment statements. `nocomment` has you covered. If you find that you want to see only the comments, you can do that too with `onlycomments`
```bash
alias onlycomments='grep "^#"'
alias nocomment='grep -v "^\s*#"'

This one is insanely useful. It launches a mini webserver that serves the current folder over HTTP.

alias serve='python3 -m http.server 8000'

This is a quicky but easy to remember way to capture network traffic. tcpdump has a ton of options that you can view with man tcpdump but sniff is a really easy command to remember.

alias sniff='sudo tcpdump -i any -n -s 0 -vv'

This is pretty handy for troubleshooting path issues in your dotfiles. It displays each path in the $PATH variable on it’s own line which is far more readable.

alias ppath='echo "$PATH" | tr ":" "\n"'

A few more for fun.

alias weather="curl -s 'wttr.in/Austin?0&n&Q&lang=en&columns=80'"
alias shrug='echo "¯\\_(ツ)_/¯"'
alias showgpt="list_chatgpt_zips"
alias list-disks='lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,LABEL'
alias zram-info='watch -n 1 "free -h; echo; zramctl; echo; swapon --show"'

A Few More Complex Examples

a local wizard

On my network, I routinely jump around between different environments. It’s nice to have safeguards to make sure a command exists before aliasing it or to check for the OS and set the alias accordingly. Some examples:

Set MOTD (neofetch) and fortune command if available

if command -v neofetch >/dev/null; then
  export DOTFILES_MOTD_CMD='neofetch'
fi

# Set fortune command
if command -v fortune >/dev/null 2>&1; then
  export DOTFILES_FORTUNE_CMD='fortune'
fi

Sometimes I want to make sure the same alias is available on different OSes with different commands. The best way I have found is with an if statement that checks the output of the uname -s command

# macOS-style `say` command on Linux using espeak
if [[ "$(uname -s)" == "Linux" ]] && command -v espeak >/dev/null; then
  alias say='espeak -s 160 -p 60 -v en-us+f2'
fi

This can be as elaborate as you like. In this example I can combine the technique above with branching logic, like so:

# 🖇 Clipboard alias setup for Bash/Zsh
# Detect OS via uname and set up clip/paste aliases accordingly
case "$(uname -s)" in
    Darwin)
        # macOS
        alias clip='pbcopy'
        alias paste='pbpaste'
        ;;

    Linux)
        # Linux (assumes xclip is installed)
        if command -v xclip >/dev/null 2>&1; then
            alias clip='xclip -selection clipboard'
            alias paste='xclip -selection clipboard -o'
        elif command -v xsel >/dev/null 2>&1; then
            # fallback to xsel if xclip is missing
            alias clip='xsel --clipboard --input'
            alias paste='xsel --clipboard --output'
        else
            echo "[WARN] No clipboard tool found (install xclip or xsel for clip/paste aliases)"
        fi
        ;;

    *)
        echo "[INFO] Clipboard aliases not set: unsupported OS ($(uname -s))"
        ;;
esac

Conclusion

Aliases are one of the great things about the Linux and Mac CLI. They let you make complex commands memorable, repetitive commands shorter, and can even be quite smart with some shell logic. The other great thing about aliases are that they’re living documentation. Instead of writing some long, hero command down and relying on copy/paste, you can simply set an alias. If you ever want to see what aliases you have defined, just run the command alias with no arguments and it will list them.

That’s it. Alias magic isn’t just for Unix wizards—it’s for power-users and everyday Joe and Jill Six-Pack who just want to get things done faster and easier.

💌 Got a favorite alias I didn’t cover? Send it my way

Good aliases are meant to be stolen. May they profit you!