A common topic in the #shell channel in the Chicago Tech Slack is what people have as shell aliases. Here are some handy aliases from my aliases.sh that runs at shell startup.

Customized ls

Most unixes have an ls for a short version of the ls command, and then ll for ls -al. Here’s my version of that.

First, the color options are different on macOS ls than Linux ls, so there are two different aliases depending on OS. The -Fp options tell ls to print symbols as annotations for the names listed in the output.

if [ "${OSTYPE:0:6}" == 'darwin' ] ; then
    # Mac has -G for color.
    alias ls='ls -GFp'
    alias ll='ls -GFp -l'
    alias ls='ls -Fp --color=auto'
    alias ll='ls -Fp --color=auto -l'

Then, if I’m on a machine that has exa installed, use that instead. exa is an enhanced version of ls, but I don’t have it installed everywhere.

# If we have exa, update ll to use it instead.
hash exa 2>/dev/null && alias ll='exa -F -l -B --git'

Git and Subversion statuses

I work with both Git and Subversion throughout the day, so I have aliases for both.

# Show me status of files, but not files Subversion doesn't recognize.
alias ssq='svn status -q'

# Show what was changed in the most recent commit.
alias sdrp='svn diff -rPREV'

# Show the log entry for the most recent commit.
alias slrp='svn log -rPREV:COMMITTED'

# Git version of "ssq" above.
alias gsq='git status -sb'
alias gpr='git pull --rebase --stat'

Show processes that use the most memory.

Ed Silva gave me this long ago. I keep it around because ps’s options are the worst to remember.

alias memusage='ps -o rss,command -waxc | sort -n'

Show my running processes.

Speaking of ps and running progresses, I originally had an alias called paga that ran ps aux | grep alester, but now it’s expanded to do a lot more, and not care what user I’m logged in as.

alias paga='ps -u "$USER" f --header -o pid,ppid,start_time,%cpu,rssize=Resident,vsize=Virtual,cmd'

The output from paga shows only my running processes and in a tree format.

  PID  PPID START %CPU Resident Virtual CMD
18022 18020 21:44  0.0     2732  155040 sshd: andy@pts/0,pts/1
18023 18022 21:44  0.0     6092  119324  \_ -bash
18726 18023 22:07  0.0     1612  155368  |   \_ ps -u andy f --header -o pid,ppid,start_time,%cpu,rssize=Resident,vsize=Virtual,cmd
18441 18022 22:05  0.0     6112  119324  \_ -bash
18662 18441 22:07  0.7     8356  152236      \_ vim .bashrc
18724 18662 22:07  0.0     1200  113184          \_ /bin/bash -c (find /) >/tmp/v0sA0Oq/11 2>&1
18725 18724 22:07 52.5     1828  120664              \_ find /

Directory jumps

up is only three characters shorter than cd .., but I don’t even want to think about it.

alias up='cd ..'
alias upup='cd ../..'

Vim aliases

I use :e in vim to open a new file, but sometimes I forget I’m in the shell, and use :e filename when I mean to use vim filename. This alias makes it work anyway.

alias ':e'=vim

I use vimdiff to show file differences all the time, but sometimes I need it to ignore whitespace. This is how.

alias vimdiffx='vimdiff -c "set diffopt+=iwhite"'

Set up an SSH tunnel.

If I’m on public wifi, I set up a tunnel to my dev machine that my web browser can proxy through. I run this tunnel command and tell my browser to use port 8080 on localhost as a SOCKS5 proxy.

alias cliffordtunnel='ssh -N -f -D8080 tunnel@clifford.petdance.com'

Dump HTTP headers

I often want to contact a website and see the HTTP headers, without the content. This command does it.

alias headerdump='curl -D- -o/dev/null'

Are any of these helpful? Should I list more about my shell setup? Let me know at andy@petdance.com.