How to set up a shortcut to a directory in Mac OS X Terminal?
You don't need a shortcut file or anything like that.
You can set up an alias in ~/.bash_profile
by adding the following line, so you just need to type myFolderShortcut
to go there (without cd
):
alias myFolderShortcut='cd /Users/danielbeck/Documents'
You also need to type the above command or
source ~/.bash_profile
to get this to take effect.
This works from any directory, but requires that your login shell be bash
(which is OS X's default)
You can, of course, create symbolic links to other directories in your home directory. Then, when you open Terminal and are in your home directory, cd
ing takes you to the linked directory.
ln -s /Users/danielbeck/Documents/Projects myProjectsDir
Then, type cd myProjectsDir
and you're there (the displayed path contains myProjectsDir
though, not Documents/Projects
).
The symbolic link will show in Finder. To hide it, type chflags -h hidden myProjectsDir
.
This will work only when you're in your home directory to start with (cd
without arguments takes you there quickly; you can type both commands on the same line: cd && cd myProjectsDir
).
I know this is old, but this might help someone.
After you follow @Daniel Beck's answer above, and add the alias to the bash_profile like he mentioned, you have to type the following in the terminal window:
source .bash_profile
This will make all your aliases work.
I've got this from this answer on stack overflow. It has worked for me. I hope it works for someone looking for this...
How Do I create a terminal shortcut to this path?
Just one thing I wanted to add, because it happened to me and took me quit some time to find the error.
I wrote
alias myFolderShortcut = 'cd /Users/danielbeck/Documents'
because I like to have spaces between my equal signs. But it gave me an error.
So after removing the spaces it worked.
So use
alias myFolderShortcut='cd /Users/danielbeck/Documents'
I hope this will help someone in the future.