Introduction
In the day-to-day of any Linux user, the terminal becomes an indispensable tool. However, typing long and repetitive commands can be tired and prone to errors. This is where the alias command comes into play, which allows you to create custom shortcuts for any instruction you often use. 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 build-in of most shells (bash, zsh, fish...) that associates a word or sequence of characters to a more complex command. When the shell finds that word, it automatically replaces it with the complete command before running it. Allies do not create new programs; they are simply text replacements that the interpreter performs in time of execution. For this reason, they are ideal for shortening long routes, combining various options or running pipes. In addition, their definition is very simple and does not require root privileges, making them accessible to any user.
Create a temporary alias
To create an alias that only lasts during the current session, just write in the terminal:alias nombre='comando a ejecutar'. For example, if you wantlllist the 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 to quickly test a shortcut before deciding whether to keep it. Remember that the name of the alias cannot contain spaces and must be defined by simple or double quotes if the command includes special spaces or characters.
Make a permanent alias
If you want your alias to persist between restarts and sessions, you must add it to one of the configuration files of your shell. In bash, the most common file is~/.bashrc; in zsh,~/.zshrc. Open the file with your favorite editor, for examplenano ~/.bashrc, and in the end add the line:alias nombre='comando a ejecutar'. Save the changes and reload the settings withsource ~/.bashrcor just open a new terminal. In this way, the alias will be available every time you start a session. You can group several aliases into commented blocks to keep the file ordered and easy to hold.
Useful examples of aliases
alias actualizar='sudo apt update && sudo apt upgrade -y'(for Debian / Ubuntu systems)alias limpiar='sudo apt autoremove && sudo apt autoclean'(disks disk space)alias gp='git pull'(quick access to pull in Git repositories)alias gcp='git checkout -'(changes to the previous branch)alias dockerc='docker ps --format "table {{.Names}}\\t{{.Image}}\\t{{.Status}}"'(sample container in table format)alias ..='cd ..'(up a directory level)alias ...='cd ../..'(raise two levels)alias md='mkdir -p'(create parent directories if they do not exist)alias h='history | grep'(search the history)
Good practices and advice
- Use short but descriptive names; avoid collisions with existing commands (e.g. 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 yourself in the future) understand their purpose.
- Always try 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; the functions allow for more advanced logic.
- Keep a backup of your configuration file (for example, in a dotfiles repository) so you can easily restore it in new machines.
Conclusion
The alias command is a simple but powerful tool that can transform the way you interact with the terminal. By reducing the amount of keyboard needed for repetitive tasks, you make time and decrease the probability of errors. Whether you are a system manager, developer or command line enthusiast, incorporating well-thought-out aliases into your environment will make your work more fluid and productive. Start creating your own shortcuts today and notice the difference!


