DEV Community

Cadell
Cadell

Posted on • Edited on

6 2

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay