So after a multi-year hiatus from living daily in the OSX world, I recently could resist the “Shinny” no longer; I broke down and purchased a MacBook Pro. Just as with every Apple product I’ve used through the years, this new rMBP 13” is a wonderful piece of hardware. But Apple’s consistently sublime hardware is not the subject of this post, but rather the software – OSX 10.9 Mavericks to be specific.

While I’ve been away form the Mac ecosystem (Snow Leopard days), many things have changed – The App Store, death of physical media, the hard drive displaying by default on the Finder’s desktop, I could go on. But one thing that has remained true as the north star is OSX’s Unix underpinnings, and where there is Unix – there is a Terminal.

As someone who’s idea of making a computer useful requires, regardless how pretty the GUI is, there is always a CMD.exe or Terminal shortcut overtly located on the desktop – you can be sure getting down to the command line on my new notebook was a top priority. With Terminal prominently situated on my dock I was ready to work – or so I thought until I started barking some of my favorite Linux/BSD commands at the window.

What the heck? No “ll” alias? And what about my other favorite behaviors? Ok, ok – surely I just need to modify the .profile (hidden file in the home folder of many *nix systems that defines the CLI’s operation.)  From the command line, I issue a “ls -al” to show me the hidden “.” files, and sure enough – no “.profile” – great, I’ll just grab one of my linux ones and be good to go. Right? Wrong!

Meet the .bash_profile file

After a little bit of digging online, I found some docs referring to the .bash_profile. Interestingly, on my fresh OSX 10.9 Mavericks build this file does not exist, not even an empty one.  So if you, like I, desire more customized control over your Terminal experience – feel free to create a .bash_profile and then use my template below to populate it. Consider it a soup starter, and you an mix in your favorite changes – Enjoy.

#     SET ENV
#   ------------------------------------------------------------
export PATH="/usr/local/:$PATH"
#
#   Set Default Editor (change 'Nano' to the editor of your choice)
#   ------------------------------------------------------------
export EDITOR=/usr/bin/nano
#
#   Set default blocksize for ls, df, du
#   ------------------------------------------------------------
export BLOCKSIZE=1k
#
#   Add color to terminal
#   ------------------------------------------------------------
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
#
#   -----------------------------
#     TERMINAL
#   -----------------------------
#
alias shome='ssh eric@xxx.yyy.xxx'          # quick SSH shortcut
alias cp='cp -iv'                           # Preferred 'cp' implementation
alias mv='mv -iv'                           # Preferred 'mv' implementation
alias mkdir='mkdir -pv'                     # Preferred 'mkdir' implementation
alias ll='ls -FGlAhp'                       # Preferred 'ls' implementation
alias less='less -FSRXc'                    # Preferred 'less' implementation
cd() { builtin cd "$@"; ll; }               # Always list directory contents upon 'cd'
alias f='open -a Finder ./'                 # f:            Opens current directory in MacOS Finder
alias ~="cd ~"                              # ~:            Go Home
alias c='clear'                             # c:            Clear terminal display
alias path='echo -e ${PATH//:/\\n}'         # path:         Echo all executable Paths
alias show_options='shopt'                  # Show_options: display bash options settings
alias fix_stty='stty sane'                  # fix_stty:     Restore terminal settings when screwed up
alias cic='set completion-ignore-case On'   # cic:          Make tab-completion case-insensitive
mcd () { mkdir -p "$1" && cd "$1"; }        # mcd:          Makes new Dir and jumps inside
trash () { command mv "$@" ~/.Trash ; }     # trash:        Moves a file to the MacOS trash
ql () { qlmanage -p "$*" >& /dev/null; }    # ql:           Opens any file in MacOS Quicklook Preview
alias DT='tee ~/Desktop/terminalOut.txt'    # DT:           Pipe content to file on MacOS Desktop
#
#   lr:  Full Recursive Directory Listing
#   ------------------------------------------
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/   /'\'' -e '\''s/-/|/'\'' | less'
#
#   ---------------------------
#     PROCESS MANAGEMENT
#   ---------------------------
#
#   findPid: find out the pid of a specified process
#   -----------------------------------------------------
#       Note that the command name can be specified via a regex
#       E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
#       Without the 'sudo' it will only find processes of the current user
#   -----------------------------------------------------
findPid () { lsof -t -c "$@" ; }
#
#     Find memory hogs
#   -----------------------------------------------------
alias memhogstop='top -l 1 -o rsize | head -20'
alias memhogsss='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'
#
#   cpuhogs:  Find CPU hogs
#   -----------------------------------------------------
alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'
#
#   topforever:  Continual 'top' listing (every 10 seconds)
#   -----------------------------------------------------
alias topforever='top -l 9999999 -s 10 -o cpu'
#
#   ttop:  Recommended 'top' invocation to minimize resources
#   ------------------------------------------------------------
#       Taken from this macosxhints article
 #       http://www.macosxhints.com/article.php?story=20060816123853639
#   ------------------------------------------------------------
alias ttop="top -R -F -s 10 -o rsize"
#
#   my_ps: List processes owned by my user:
#   ------------------------------------------------------------
my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }

#
#   ---------------------------
#     NETWORKING
#   ---------------------------
#
alias myip='curl ip.appspot.com'                    # myip:         Public facing IP Address
alias netcons='lsof -i'                             # netCons:      Show all open TCP/IP sockets
alias flushdns='dscacheutil -flushcache'            # flushDNS:     Flush out the DNS Cache
alias lsock='sudo /usr/sbin/lsof -i -P'             # lsock:        Display open sockets
alias lsocku='sudo /usr/sbin/lsof -nP | grep UDP'   # lsockU:       Display only open UDP sockets
alias lsockt='sudo /usr/sbin/lsof -nP | grep TCP'   # lsockT:       Display only open TCP sockets
alias ipinfo0='ipconfig getpacket en0'              # ipInfo0:      Get info on connections for en0
alias ipinfo1='ipconfig getpacket en1'              # ipInfo1:      Get info on connections for en1
alias openports='sudo lsof -i | grep LISTEN'        # openPorts:    All listening connections
alias showblocked='sudo ipfw list'                  # showBlocked:  All ipfw rules inc/ blocked IPs