How to Create and Use Aliases on Arch Linux
Categories:
5 minute read
Aliases are a powerful and convenient feature in Linux that allows you to customize your command-line experience by creating shortcuts for commonly used commands. On Arch Linux—a distribution known for its simplicity and user-centric design—aliases can significantly enhance productivity and reduce repetitive typing.
In this guide, we’ll explore what aliases are, how to create and manage them, and how to make the most of them on your Arch Linux system.
What Are Aliases in Linux?
In the context of Linux, an alias is essentially a shortcut or shorthand for a longer command. For example, instead of typing:
ls -lah --color=auto
you can create an alias called ll
so that typing ll
executes that entire command.
Aliases are typically used to:
- Save time.
- Avoid repetitive typing.
- Prevent mistakes in frequently used complex commands.
- Customize the shell to suit personal preferences.
Temporary vs. Permanent Aliases
Before jumping into creating aliases, it’s important to distinguish between temporary and permanent aliases.
- Temporary aliases exist only for the duration of the current shell session. Once you close the terminal, they’re gone.
- Permanent aliases are stored in shell configuration files and are available every time you open a new terminal session.
Let’s look at how to create both.
Creating Temporary Aliases
To create a temporary alias, use the following syntax:
alias shortname='command'
Example
alias ll='ls -lah --color=auto'
Now, typing ll
in the terminal will display a colorized and detailed list of directory contents. However, once you close the terminal or log out, the alias disappears.
Creating Permanent Aliases on Arch Linux
To make an alias permanent, you need to add it to your shell configuration file. On Arch Linux, the default shell for many users is bash, but some may use zsh, fish, or other shells. We’ll focus on bash and zsh, the two most common ones.
For Bash Users
- Open the
.bashrc
file in your home directory:
nano ~/.bashrc
- Add your alias at the end of the file:
alias ll='ls -lah --color=auto'
alias gs='git status'
alias update='sudo pacman -Syu'
Save and exit (Ctrl + O, Enter, Ctrl + X in nano).
Reload the
.bashrc
file or restart your terminal:
source ~/.bashrc
For Zsh Users
- Open the
.zshrc
file:
nano ~/.zshrc
- Add aliases as you would in
.bashrc
:
alias ll='ls -lah --color=auto'
alias gs='git status'
alias update='sudo pacman -Syu'
- Save and reload:
source ~/.zshrc
Best Practices for Creating Aliases
Here are a few tips to make your alias management cleaner and more effective:
1. Use Meaningful Names
Choose names that are short but descriptive. For example, update
is more intuitive than up
when updating packages.
2. Avoid Overwriting Built-in Commands
Avoid naming aliases with the same name as system commands unless you’re intentionally overriding them.
3. Use Quotation Marks
Always wrap the command in single quotes ('
) to prevent immediate evaluation and ensure proper handling of special characters.
4. Group Aliases by Function
For better organization, group your aliases (e.g., general, git, pacman, networking) using comments.
Example:
# General aliases
alias ll='ls -lah --color=auto'
alias ..='cd ..'
# Git aliases
alias gs='git status'
alias gc='git commit -m'
# Pacman aliases
alias update='sudo pacman -Syu'
alias install='sudo pacman -S'
Advanced Alias Usage
Aliases are not limited to simple one-liners. You can use them in more complex scenarios too.
Using Aliases with Arguments
Basic aliases don’t accept arguments. For example:
alias sayhello='echo Hello'
Typing sayhello world
won’t pass world
as an argument.
Workaround: Use Functions Instead
When you need parameterized behavior, define a function in your shell configuration file instead:
sayhello() {
echo "Hello, $1"
}
Now, sayhello world
will output Hello, world
.
Aliases with Piped Commands
You can create aliases that include pipes or redirection:
alias searchlog='grep "ERROR" /var/log/syslog | less'
This lets you quickly filter log files for errors and page through them.
Using a Separate Aliases File
To keep your configuration clean and modular, you can store aliases in a dedicated file, like ~/.bash_aliases
or ~/.zsh_aliases
.
For Bash
- Create
~/.bash_aliases
:
nano ~/.bash_aliases
Add your aliases.
Include this file in your
.bashrc
:
# At the bottom of ~/.bashrc
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
- Reload:
source ~/.bashrc
For Zsh
- Create
~/.zsh_aliases
:
nano ~/.zsh_aliases
- Add aliases and include them in
.zshrc
:
# At the bottom of ~/.zshrc
if [ -f ~/.zsh_aliases ]; then
source ~/.zsh_aliases
fi
- Reload:
source ~/.zshrc
Managing Aliases: Listing and Removing
Listing All Aliases
To see a list of all currently active aliases:
alias
This shows all aliases in the current shell session.
Removing an Alias Temporarily
To remove an alias for the current session:
unalias ll
Removing a Permanent Alias
- Open your config file (
.bashrc
,.zshrc
, or.bash_aliases
). - Remove or comment out the line with the alias.
- Save and reload the file.
Useful Aliases for Arch Linux Users
Here are some handy alias suggestions tailored for Arch Linux:
# System updates
alias update='sudo pacman -Syu'
alias clean='sudo pacman -Rns $(pacman -Qdtq)'
# Package management
alias search='pacman -Ss'
alias install='sudo pacman -S'
alias remove='sudo pacman -Rns'
alias info='pacman -Qi'
# AUR helpers (e.g., yay)
alias yupdate='yay -Syu --noconfirm'
alias yclean='yay -Yc'
# File navigation
alias ..='cd ..'
alias ...='cd ../..'
alias c='clear'
# Networking
alias myip='curl ifconfig.me'
# Git
alias gs='git status'
alias ga='git add'
alias gc='git commit -m'
alias gp='git push'
alias gl='git log --oneline --graph --decorate'
Troubleshooting Aliases
Alias Not Found?
- Make sure the alias is in the right configuration file.
- Check that the file is sourced (
source ~/.bashrc
). - Confirm there are no syntax errors in the file.
- Reopen your terminal or source the file after editing.
Aliases Not Working in Scripts?
Aliases work in interactive shells by default, not in non-interactive shell scripts. Use full commands or functions in scripts instead.
Conclusion
Aliases are a simple yet powerful tool that can help you work more efficiently on Arch Linux. Whether you’re a power user who works in the terminal all day or a casual user looking to streamline a few tasks, aliases can save time and reduce friction.
By understanding how to create, manage, and organize aliases—both temporary and permanent—you gain greater control over your shell environment. Start with a few helpful aliases, and gradually build your own personalized command toolkit.
Arch Linux is all about user control, and aliases are a perfect example of how you can tailor your system to suit your workflow. Take advantage of them—you’ll wonder how you ever lived without them.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.