DEV Community

100x.crypto πŸš€πŸš€
100x.crypto πŸš€πŸš€

Posted on

Boost your terminal workflow with aliases

If you often work in the terminal, you've probably found yourself looking up and typing the same long commands again and again. Whether it's starting a service, launching a Docker container, or running a script, those commands are hard to remember and slow you down your workflow.

Fortunately, there's a simple trick that makes your life much easier: aliases

An alias is a short, memorable word you define to stand in for a longer command. It's one of the simplest and most powerful ways to make your command-line experience faster, cleaner, and more enjoyable.

Let's see how it works. πŸ‘‡

πŸš€ Example

Imagine you're frequently running these two commands:

sudo service docker start
sudo docker run -it ubuntu:22.04 bash
Enter fullscreen mode Exit fullscreen mode

The first starts the Docker service, and the second launches a fresh Ubuntu container (see my other blog post to learn where this combination can be helpful). Both are useful, but memorizing and typing them every time is tedious.

With aliases, you can replace those long commands with simple, human-friendly words like:

startdocker
freshubuntu
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ Step 1: Create temporary aliases (for testing)

You can define an alias directly in your terminal. It will work until you close the session:

alias startdocker='sudo service docker start'
alias freshubuntu='sudo docker run -it ubuntu:22.04 bash'
Enter fullscreen mode Exit fullscreen mode

Now try them:

startdocker
freshubuntu
Enter fullscreen mode Exit fullscreen mode

Much cleaner and easier to remember.

If you want to change the command associated with an alias, just redefine it with the new command. The new definition will overwrite the old one.

Note: You need to have Docker installed to run these commands. If you don't have Docker, either install it via

sudo apt update
sudo apt install docker.io -y
Enter fullscreen mode Exit fullscreen mode

...or try other commands you use frequently.

πŸ” Step 2: Make aliases permanent

Temporary aliases disappear when you close the terminal. To make them permanent, add them to your shell configuration file.

For bash (Ubuntu's default shell):

nano ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Then add your aliases at the bottom:

alias startdocker='sudo service docker start'
alias freshubuntu='sudo docker run -it ubuntu:22.04 bash'
Enter fullscreen mode Exit fullscreen mode

Save and exit (CTRL+O, Enter, CTRL+X), then reload the configuration:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Now these aliases will work every time you open a new terminal window.

Note: If you're using zsh instead of bash, add aliases to ~/.zshrc instead of ~/.bashrc.

πŸ”— Combine multiple commands into a single alias

Aliases can do more than just shorten single commands. They can chain multiple commands together.

For example, you could create an alias that starts Docker and then launches the container:

alias freshubuntu='sudo service docker start && sudo docker run -it ubuntu:22.04 bash'
Enter fullscreen mode Exit fullscreen mode

Now, typing:

freshubuntu
Enter fullscreen mode Exit fullscreen mode

…will automatically start the Docker service (if needed) and drop you into a fresh Ubuntu environment, all in one step.

🧠 Useful tips

  • Command to list all defined aliases:
alias
Enter fullscreen mode Exit fullscreen mode

Note: Some aliases may already be defined by default in your system’s .bashrc or other startup files.

  • Command to remove an alias:
unalias freshubuntu
Enter fullscreen mode Exit fullscreen mode
  • Best practices:
    • Use short, meaningful names.
    • Keep a consistent naming convention (e.g., all lowercase).

πŸ“‚ Optional: Store aliases in a separate file

As your list of aliases grows, it can clutter your ~/.bashrc. A cleaner approach is to store them in a dedicated ~/.bash_aliases file and then load that file from .bashrc.

Step 1 – Create the .bash_aliases file:

nano ~/.bash_aliases
Enter fullscreen mode Exit fullscreen mode

Add your shortcuts:

alias startdocker='sudo service docker start'
alias freshubuntu='sudo docker run -it ubuntu:22.04 bash'
Enter fullscreen mode Exit fullscreen mode

Save and exit the file (CTRL+O, Enter, CTRL+X).

Step 2 – Source it from .bashrc:

Open your ~/.bashrc and add this snippet near the bottom:

if [ -f ~/.bash_aliases ]; then
    source ~/.bash_aliases
fi
Enter fullscreen mode Exit fullscreen mode

This tells your shell to load all aliases from ~/.bash_aliases if the file exists.

Note: You may already have this if-block in your .bashrc file.

Now your ~/.bashrc stays clean, and you can back up or share your aliases separately without touching the rest of your configuration.

This small structure change pays off later, especially when you start version-controlling your config (as we'll explore in the next post).

✨ Conclusion

Aliases are a small trick that deliver big productivity gains. With just a few lines in your shell config, you can turn long, hard-to-remember commands into short, memorable shortcuts, saving time and making your workflow more enjoyable.

Note: I use ChatGPT to help me gather information and shape these posts, but I always test the commands myself and add my own insights to make them easier to understand. This blog is my personal record of what I learn as I go deeper into Linux. If it helps someone else too, even better!

Top comments (0)