⚡ Command: alias (Create Your Own Shortcuts)
The alias command allows you to create short, custom nicknames for long or complex terminal commands. Think of it as a way to "program" your terminal to understand your own personal shorthand.
1. The "Why"
On Arch Linux, you likely spend a lot of time in the terminal. Using alias can save you thousands of keystrokes over time.
- Simplify Maintenance: Shorten long commands like
sudo pacman -Syuto justupdate. - Project Shortcuts: Quickly jump into your Preader or e-book directories.
- Prevent Mistakes: Add safety flags (like
-ifor interactive) to dangerous commands likermso they ask before deleting. - Efficiency: Automate repetitive tasks, like starting your Supabase local environment or reloading Hyprland.
2. Basic Syntax
alias name='command'
- Note: There must be no spaces around the
=sign.
3. Practical Examples for Your Workflow
A. System Maintenance (Arch Linux)
Instead of typing the full update command every day:
alias update='sudo pacman -Syu'
B. Navigation Shortcuts
Stop typing long paths to your project folders:
alias cdbook='cd ~/Documents/projects/ecommerce-blueprint'
alias cddev='cd ~/Documents/dev/java/preader'
C. Safety First
Force the terminal to ask "Are you sure?" before deleting or overwriting files:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
D. Development Tools
If you frequently use python3 but prefer typing py, or want a quick way to check your IP:
alias py='python3'
alias myip='curl ifconfig.me'
4. How to Make Aliases Permanent
If you just type an alias into the terminal, it will disappear the moment you close the window. To make them stay forever, you must add them to your shell's configuration file.
- Identify your shell: (You are likely using Bash or Zsh).
- Open the config file:
- For Bash:
nano ~/.bashrc - For Zsh:
nano ~/.zshrc
- For Bash:
- Paste your aliases at the bottom of the file.
- Save and reload:
source ~/.bashrc(or just restart your terminal).
5. Managing Aliases
- List all active aliases: Just type
aliasby itself. - Remove an alias (temporarily): Use
unalias name. - Bypass an alias: If you have an alias like
alias ls='ls -a'but want to run the originallsjust once, type a backslash before it:\ls.
6. Pro-Tips
- Complex Aliases: If a command is extremely long or requires logic (if/else), you should use a Function instead of an alias.
- Arch Linux Context: Many Arch users create an alias for the AUR helper. For example:
alias p='yay'oralias p='paru'. - Productivity: You can create an alias to reload your Hyprland config or Waybar after you've made edits, saving you the time of killing and restarting the process manually.
7. Summary Reference
| Goal | Command Example |
|---|---|
| Create temporary alias | alias ll='ls -lah' |
| View all aliases | alias |
| Remove an alias | unalias ll |
| Permanent Alias | Add to ~/.bashrc or ~/.zshrc |