In Linux, the
alias command is a simple but powerful tool that allows users to
create shortcuts or custom commands for longer commands. This can improve your
workflow and speed up tasks. In this article, we'll explore how to create custom
alias, discuss the life cycle of these commands, and detail
various options available for the
At its core,
alias allows you to assign a new name (alias) to a command or
sequence of commands. The basic syntax for creating an alias is:
alias l='ls -l'
With this alias set, typing
l will now execute the
ls -l command.
Examples of Custom Commands Using
Many users prefer colored output for the
alias ls='ls --color=auto'
2. Shortening Git Commands
If you frequently use git, you might find these shortcuts handy:
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
3. Navigation Shortcuts
alias ..='cd ..'
alias ...='cd ../..'
4. Enhanced Directory Listing
To list directories first, followed by files:
alias ll="ls -lv --group-directories-first"
5. Safety Nets
Protect against accidental deletions:
alias rm='rm -i'
-i option prompts you before removing a file.
Life of an Alias
Creation: As shown above, aliases are created using the
aliascommand followed by the custom command name and the command it represents.
Duration: By default, an alias created on the command line is temporary. It lasts only for the current session. If you close the terminal or log out, the alias is gone.
Persistence: To make an alias permanent, you can add it to your shell’s configuration file, such as
~/.bashrcfor the Bash shell. After adding, you can use
source ~/.bashrcor just open a new terminal to have the alias available.
Removal: To remove an alias, use the
unaliascommand followed by the alias name, e.g.,
Viewing Aliases: To view all currently defined aliases, simply type
aliaswithout any arguments.
alias itself doesn't have a wide range of options like other
Linux commands. Its main purpose is to define or check aliases. However, in
relation to managing aliases, there's
unalias for removing them. Here's a
table for clarity:
|Display a list of all defined aliases in the current session.|
|Display the command assigned to a specific alias.|
|Create a new alias.|
|Remove an alias.|
|Remove all defined aliases.|
alias command in Linux is a practical tool for streamlining your
command-line operations. By creating custom commands that fit your workflow, you
can enhance productivity and reduce the chances of errors. Remember to add
frequently used aliases to your shell's configuration file to ensure they are
available in every session.
What Can You DO Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.