Mobile
My iOS apps
Other apps
Open source
  • Bandwidth benchmark
  • RAVM virtual machine
  • Big integer division
  • Prime numbers
  • AntiJOP sanitizer
  • TouchWidgets UI lib
  • Networking utils
  • 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
  • Vocal programming
  • Nutrition
  • 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
    }
    
    # Compare all files in dirs byte for byte:
    function ca {
            if [ "$1" == "" ]; then
                    echo No parameters
            else
            if [ "$2" == "" ]; then
                echo Missing 2nd parameter
            else 
                for s in $1/*; do
                    if cmp -s "$1/$s" "$2/$s"; then
                        echo Files are the same
                    else
                        echo Files are different
                        echo 1: $1/$s
                        echo 2: $2/$s
                    fi
                done
            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

    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/
    }
    

    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 h=history
    • alias e=vi



    © Zack Smith