Alias Essentials: A Step-by-Step Guide to Creating Terminal Shortcuts

As a web developer, we are no strangers to playing in the terminal. Whether running scripts, managing files, or installing packages, you rely on terminal commands to streamline your workflow.

However, long and complex command sequences can slow you down and hinder productivity. That's where creating custom alias commands come in handy.

This article will guide you through creating alias commands in the terminal, allowing you to work more efficiently and effectively.

Anonymous hacker mask with an overlay of code

What are Alias Commands?

Alias commands are shorthand versions of longer commands that you frequently use.

They can be easily created and customized to suit your specific needs.

Creating an alias command allows you to execute a long command sequence by typing just a few characters, saving time and minimizing the chances of making errors.

Let's jump into creating aliases. 👇

Temporary Aliases

Creating a temporary alias is a simple process. In your terminal, type the following:

alias short_command="your_long_command"

For example, if you frequently list the contents of a directory with the -l flag to view them in a detailed format, you can create an alias for this command:

alias ll="ls -l"

Now, whenever you type ll in the terminal, it will execute ls -l instead.

Remember that temporary aliases will only last for your current terminal session.

Persistent Aliases

You'll need to add the alias to your shell's configuration file to create a persistent alias that remains available across different terminal sessions and system restarts.

For Bash users

Open your .bashrc file in your favorite text editor, for ease I'm using nano:

nano ~/.bashrc

Add your alias to the bottom of the file:

alias short_command="your_long_command"

Save the changes and exit the text editor. Either restart your terminal so the aliases are available or else to apply the changes immediately, run:

source ~/.bashrc

For Zsh users

The process is similar, but you'll need to edit the .zshrc file instead:

nano ~/.zshrc

Then restart your terminal to apply the changes.


If you are not using Bash or Zsh, a quick search on the internet will help you find the config file name so you can find it and modify it.

Best Practices for Creating Aliases

  • Choose concise and descriptive names for your aliases that are easy to remember.
  • Group related aliases together in your shell's configuration file for better organization.
  • Add comments to your configuration file to explain the purpose of each alias.
  • Regularly review and update your aliases to ensure they remain relevant to your workflow.

Leave a comment below with your favorite one. 👇

Follow me on Twitter or connect on LinkedIn.

🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉

LinuxShellCommand LineTerminalProductivity
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.