Open source
  • Bandwidth benchmark
  • TouchWidgets UI lib
  • Diviner big number math
  • Documentation
  • x86 instructions ref
  • GIT quick ref
  • GPG quick ref
  • Avoid Ubuntu
  • Android malware risks
  • iOS malware risks
  • OS/X security tips
  • Who blocks Tor
  • Software engineering
  • BASH aliases
  • I.B. pro/con
  • Nutrition
  • Other apps
  • Blog
  • Contact
    1 at zsmith dot co

    The best BASH aliases

    Document revision 6
    © by
    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
    export W=~/Downloads
    

    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 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 UM='git pull origin master'
    • alias AM='git add *.[mhc]'
    • alias S='git status'
    • alias L='git log'
    • alias C='git commit'

    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

    Et cetera

    • alias a=alias
    • alias .p="source ~/.profile"
    • alias ep="vi ~/.profile"
    • alias e=vi
    • alias h=history



    © Zack Smith