Make shortcuts to directories via terminal

I keep aliases in ~/.bash_profile.

Terminal and iTerm 2 open new shells as login shells by default. When bash is invoked as an interactive login shell, it reads ~/.bash_profile but not ~/.bashrc. The terminal emulators on other platforms often open new shells as non-login shells, so for example bash reads ~/.bashrc but not ~/.bash_profile. OS X users often use ~/.bash_profile as the personal configuration file corresponding to ~/.bashrc on other platforms, but it is also possible to source ~/.bashrc from ~/.bash_profile or to tell Terminal or iTerm 2 to open new shells as non-login shells.

If both ~/.profile and ~/.bash_profile exist, bash only reads ~/.bash_profile when it is invoked as an interactive login shell. ~/.profile is also used by other shells and programs that might not understand the same configuration options as bash.

/etc/bashrc is owned by root, and it might get replaced when you upgrade OS X.

See man bash|less +^INVOCATION or https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html for more information.


Typically you put alias definitions into the same file as your $PATH definitions which is probably ~/.bashrc.


Technically speaking an alias is not a shortcut to a folder but for any shell command. So you can also have things like

alias heal='xattr -d com.apple.quarantine'
alias la='ls -lFa'
alias ll='ls -lF'
alias ls='ls -FG'
alias show-path='echo -e ${PATH//:/\\n}'

to make your life easier. Aliases are replaced as-is by the shell so if you run

heal downloadedFile.dmg

it gets expanded to

xattr -d com.apple.quarantine downloadedFile.dmg

and executed afterwards. If you need more flexibility with parameters you may want to look into shell functions (but that probably should go into another question).