Create shell command aliases for your commonly used commands
Why create shell aliases
Shell aliases can save you keystrokes, which save time. That time saved is compound interest over long time horizons!
How to create aliases
Shell aliases are easy to create. In your shell initializer script, use the following syntax, using ls
being aliased to exa
with configuration flags at the end as an example:
alias ls="exa --long"
Now, typing ls
at the shell will instead execute exa
! (To know what is exa
, see Install and configure system-wide software.)
Where to store these aliases
In order for these shell aliases to take effect each time you open up your shell, you should ensure that they get sourced in your shell initialization script (see: Take full control of your shell environment variables for more information). You have one of two options:
- These aliases can be declared in your
.zshrc
or.bashrc
(or analogous) file, or - They can be declared in
~/.aliases
, which you source inside your shell initialization script file (i.e..zshrc
/.bashrc
/etc.)
I recommend the second option as doing so means you'll be putting into practice the philosophy of having clear categories of things in one place.
For managing aliases across multiple machines, see using dotfiles for environment management. This approach helps you keep your aliases consistent and portable.
For configuring your shell editor to work well with aliases, see shell-based editors setup. A well-configured editor can complement your aliases for maximum productivity.
Useful aliases to get started
In my dotfiles repository, I have a .shell_aliases
directory which contains a full suite of aliases that I have installed.
Other external links that showcase shell aliases that could serve as inspiration for your personal collection include:
- Bash aliases you can't live without
- 10 handy Bash aliases for Linux
- vikaskyadav/awesome-bash-alias
- 30 Handy Bash Shell Aliases For Linux / Unix / MacOS
- A developer's way of using shell aliases
And finally, to top it off, Twitter user @ctrlshifti suggests aliasing please to sudo for a pleasant experience at the terminal:
alias please="sudo"
# Now you type:
# please apt-get update
# please apt-get upgrade
# etc...