Introduction
In the day-to-day of any Linux user, the terminal becomes an indispensable tool. However, typing long and repetitive commands can become tiring and prone to errors. This is where the alias command comes into play, allowing you to create custom shortcuts for any instruction you use frequently. In this article you will discover what an alias is, how to define it temporarily or permanently, and you will see practical examples that will make your workflow much more agile.
What is the alias command?
The alias command is a built‑in of most shells (bash, zsh, fish…) that associates a word or character sequence with a more complex command. When the shell encounters that word, it automatically substitutes it with the full command before executing it. Aliases do not create new programs; they are simply text substitutions that the interpreter performs at runtime. For this reason, they are ideal for shortening long paths, combining several options, or chaining pipelines. Moreover, their definition is very simple and does not require root privileges, making them accessible to any user.
Creating a temporary alias
To create an alias that lasts only for the current session, simply type in the terminal: alias name='command to execute'. For example, if you want ll to list files with details and colors, you can type: alias ll='ls -l --color=auto'. This alias will be available until you close the terminal or start a new shell. It is useful for quickly testing a shortcut before deciding whether to keep it. Remember that the alias name cannot contain spaces and must be delimited by single or double quotes if the command includes spaces or special characters.
Making a permanent alias
If you want your alias to persist across reboots and sessions, you need to add it to one of your shell’s configuration files. In bash, the most common file is ~/.bashrc; in zsh, ~/.zshrc. Open the file with your favorite editor, for example nano ~/.bashrc, and at the end add the line: alias name='command to execute'. Save the changes and reload the configuration with source ~/.bashrc or simply open a new terminal. This way, the alias will be available each time you start a session. You can group several aliases in commented blocks to keep the file tidy and easy to maintain.
Useful alias examples
alias update='sudo apt update && sudo apt upgrade -y'(for Debian/Ubuntu systems)alias clean='sudo apt autoremove && sudo apt autoclean'(frees up disk space)alias gp='git pull'(quick access to pull in Git repositories)alias gcp='git checkout -'(switches to the previous branch)alias dockerc='docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"'(shows containers in table format)alias ..='cd ..'(go up one directory level)alias ...='cd ../..'(go up two directory levels)alias md='mkdir -p'(create parent directories if they don’t exist)alias h='history | grep'(search in history)
Best practices and tips
- Use short but descriptive names; avoid collisions with existing commands (for example, do not use
alias ls='ls -l'if that breaks scripts that depend on the original output). - Document your aliases in a README file or in comments within your bashrc so that others (or you in the future) understand their purpose.
- Always test an alias in a temporary session before making it permanent.
- If an alias becomes too complex, consider creating a shell function or a separate script; functions allow more advanced logic.
- Keep a backup of your configuration file (for example, in a dotfiles repository) so you can easily restore it on new machines.
Conclusion
The alias command is a simple yet powerful tool that can transform the way you interact with the terminal. By reducing the amount of typing needed for repetitive tasks, you save time and decrease the likelihood of errors. Whether you are a system administrator, developer, or command‑line enthusiast, incorporating well‑thought‑out aliases into your environment will make your work smoother and more productive. Start creating your own shortcuts today and notice the difference!
This post is also available in ESPAÑOL.