Hey Apple – Where’s the stinkin’ .Profile?
Posted on March 12th, 2014 in Apple, Linux/Unix | No Comments »
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