Terminal 101: Creating Aliases for Commands

Every Monday (or in this case, Tuesday), we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!

While using Terminal, you may discover that you constantly run a string of commands so often, it's ridiculous that you have to type them in at all. Well, just as you can create shortcuts to applications and automate actions in OS X, you can also do so for Terminal commands that are in constant rotation. These are called aliases, and you can set them up to run temporarily or permanently through your Mac’s command line interface.

Creating a Temporary Alias

To create a temporary alias that is good for the current terminal session, you will use the following format to create the alias:

alias new_name='command to be performed'

Just about any command can be used to create an alias, but we'll use this sample command throughout this how to. This command will let us jump to our Documents folder just by typing in "documents":

alias documents='cd /Documents'

Once the command has been assigned to its alias, you can type in the alias name followed by the enter key to perform the action assigned to the alias.

Recording Aliases Permanently

If you assign an alias using the above method, then it will only be available for the current terminal session. Once you close the terminal window, the alias will no longer be available. To make the alias permanent, you will need to edit a file called “.bash_profile” by running the following command:

nano /.bash_profile

This will open nano (a command line text editor). Use the arrow keys to place the cursor at the bottom of the file, and type in the aliases that you wish to use, one per line, just as you did when creating temporary aliases. When you are done, press Control + O (Write Out) to save the file. Press Command + X to exit nano and go back to the command line.

When you quit and re-open the Terminal application, your aliases will work without having to re-create them each time.

Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.

TOPICS
Latest in Macs
Apple Mac Mini on wood desk
Forget President’s Day sales, Apple is selling an M2 Mac mini refurb for just over $300 which could be the PC bargain of the year
Sergii Figurnyi
Apple's M5 chip is rumored to be in mass production - but we're still waiting for M4 MacBook Airs
A hand holding up the new Mac mini M4
Apple's M4 Mac mini might be one of the best Macs ever, but it has a serious issue that needs fixing right now
Mac mini vs. iMac
Mac mini M4 vs iMac M4: Which is the one for you?
Mac mini vs. Mac Studio
Mac mini M4 vs Mac Studio M2: Which is the one for you?
Mac mini vs Mac Pro
Mac mini M4 vs Mac Pro M2: Which is the one for you?
Latest in How Tos
PSV Eindhoven forward Luuk de Jong and PSV Eindhoven forward Ivan Perisic play ahead of the PSV vs Arsenal Champions League last 16 match on March 4, 2025 (Photo by Marcel van Dorst / EYE4images/NurPhoto via Getty Images)
PSV vs Arsenal live stream: How to watch Champions League game online, worldwide streaming info, kick off time
Varun Chakravarthy of India celebrates victory with teammate Shreyas Iyer after defeating New Zealand during the ICC Champions Trophy 2025 match and making it to the India vs Australia semi-final of the ICC Champions Trophy
India vs Australia live stream: Watch ICC Champions Trophy semi-final online from anywhere
Host Conan O'Brien poses with an Academy Award in a promotional image for The Oscars 2025
Where to watch the Oscars 2025: replay 97th Academy Awards from anywhere, full highlights, catch-up
Davis vs Roach live stream: how to watch boxing online, cheapest PPV deals, start time, undercard
Davis vs Roach live stream: how to watch boxing online today, cheapest PPV deals, start time, undercard underway soon
An option to change Apple Intelligence language in iOS 18.4.
How to change Apple Intelligence settings: take control of Apple AI
Apple’s new Invites app gives iCloud Plus subscribers an easier way to organize parties – and Android fans are invited too
How to use Apple Invites: creating and responding to invitations on iPhone