DEV Community

Cadell
Cadell

Posted on • Edited on

Creating Terminal Shortcuts with Aliases

If you're like me and live in the terminal, creating shortcut commands known as aliases for regularly accessed directories can save you a bunch of time. You create these aliases in your .bash_profile. Let me show you how.

For me, before I created an alias, accessing my directory that contained all my school documents was a chore... this is what it looked like.

cd ~/Documents/Documents\ -\ Cadell’s\ MacBook\ Air/UTT\ year\ 1\ semester3
Enter fullscreen mode Exit fullscreen mode

To make life easier, I created an alias in my bash profile. First I opened it using:

open ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Now with my .bash_profile file opened up, I can insert the alias command.

alias school="cd ~/Documents/Documents\ -\ Cadell’s\ MacBook\ Air/UTT\ year\ 1\ semester3/"
Enter fullscreen mode Exit fullscreen mode

From here, all I need to do is save that file and relaunch terminal. Now to access my school files all I need to do is launch the school shortcut like so:

cadellsingh$ school
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
moopet profile image
Ben Sinclair

This is more of a Bash thing than a MacOS thing.

Handy tip: if you put your aliases in a file of their own and call that from your startup script instead, you can re-run that file from the command line without having to restart your terminal. I mean you could just do . ~/.bash_profile but that would be annoying if there was anything in there that you didn't want to run twice.