Your browser did not provide a language setting.

This is typical when surrepticious scraping is being performed.
The best BASH aliases

zsmith.co

The best BASH aliases

Document revision 8
© 2016-2018 by Zack Smith. All rights reserved.

The list

Directories

  • alias ..='cd ..'
  • alias ...='cd ../..'
  • alias D='cd ~/Desktop'
  • alias W='cd ~/Downloads'
  • alias V2='cd mount| grep /dev/disk2| sed "s/^.* on //" '
  • alias V3='cd mount| grep /dev/disk3|sed "s/^.* on //" '

 export D=\~/Desktop

Files and file system

  • alias df='/bin/df -h'
  • alias du='/usr/bin/du -h'
  • alias gg='du | grep "G "' # tab char after the G
  • alias f='find . -name '
  • alias g=grep
  • alias gr='grep -R '
  • alias o=open

Compare two files byte for byte:

 function c {
   if [ "$1" == "" ]; then
    echo No parameters
   else
    if [ "$2" == "" ]; then
      echo Missing 2nd parameter
    else
      if cmp -s "$1" "$2"; then
       echo Files are the same
      else
       echo Files are different
      fi
    fi
   fi
 }

Recursive comparison of all files in two dirs byte for byte:

 function car {
   if [ "$1" == "" ]; then
    echo No parameters
   else
    if [ "$2" == "" ]; then
      echo Missing 2nd parameter
    else
      cd "$1"
       find . -not -name "\.localized" \
           -not -name "*DS_Store*" \
           -not -name "\.git" \
           -type f \
           -not -exec cmp -b {} "$2"/{} ";" -print
    fi
   fi
 }

The built-in fc command is not very useful, so let's replace it with a function to count files:

 function fc {
   ls $1 | wc -l
 }

Multimedia

  • alias ll='ls -alh'
  • alias lt='ls -trs'
  • alias l3='ls -lh *.mp3 *.wav *.au *.m4a *.ogg'
  • alias 3=afplay
  • alias l4='ls -lh *.mp4 *.mov *.mkv *.m4v *.webm *.mpg *.avi *.flv'
  • alias 4='mplayer -cache 8192 '
  • alias lf='ls -lh *.pdf'

Networking

  • alias n='lsof -i'
  • alias ns='nslookup -a'
  • alias aa='arp -a'
  • alias ww=whois

Math

  • alias bc='/usr/bin/bc -l'

Making

  • alias m=make
  • alias mc='make clean'
  • alias em='vi Makefile'
  • alias co='./configure'
  • alias ch='./configure -h'

 function smi {
   sudo make clean
   sudo make install
 }

GIT

  • alias ,a='git add '
  • alias ,s='git status '
  • alias ,c='git commit '
  • alias ,o='git clone '
  • alias ,l='git log '
  • alias ,p='git push'
  • alias ,u='git pull'
  • alias ,r='git rm '

MacOS (formerly OS/X)

The Mac doesn't have an lsusb like Linux has. That's easy to fix:

  • alias lsusb='system_profiler SPUSBDataType'

Also unlike Linux, macOS doesn't have a free command to tell us how much RAM is in use. So, let's make one:

 function free {
  top -l 1 -s 0 | grep PhysMem | sed s/PhysMem/RAM/
 }

Again, unlike Linux there is no /proc directory to present system information to you. You often need to use the sysctl command. For instance, to get the CPU temperature on a Mac, you can use this alias.

 alias te='sysctl machdep.xcpm.cpu_thermal_level | \
     sed '\''s/machdep.xcpm.cpu_thermal_level/CPU temperature/'\'''
 

Disk operations:

 function eject {
   diskutil eject /dev/disk$1
 }

 function unmount {
   diskutil unmount /dev/disk$1
 }

  • alias V='cd /Volumes'
  • alias v='diskutil list' # list volumes

Colorize

 export LS_OPTIONS='--color=always'
 export GREP_OPTIONS='--color=always'

Et cetera

  • alias a=alias
  • alias e=vi
  • alias h=history