Added on Mar 4th, 2015 and marked as cli shell

Add aliases

Bash has a useful feature to make an alias to a command you often use. It’s essentially a shortcut or abbreviation for the longer command sequence. For instance, if you find yourself using often the command ls -alF you can create an alias for it.

Just add it to the file ~/.bashrc. Open it with your favorite editor and add the following lines:

alias ll='ls -alF'

Reload .bashrc (or start a new terminal session):

source ~/.bashrc

Now you can use the command ll to display directory listings.

WP-CLI

An alias I often use is for WP-CLI. You’re not allowed to run wp as root. It is therefore better to run it as the user that is also used to run the website (for instance www-data). Add this line to /root/.bashrc to fix this issue:

alias wp="sudo -u www-data -- wp"

Look up aliases

Single alias

If you need to know what specific command is executed when you run an alias, you can use the type command:

$ type ls
ls is aliased to `ls --color=auto'

$ type wp
wp is aliased to `sudo -u www-data -- wp'

All aliases

When you do not know exactly which commands are aliased, you can use the compgen command to list all available aliases:

$ compgen -a
egrep
fgrep
grep
l
la
ll
ls

ZSH?

“What about zsh?” you might ask. The answer is short, it is exactly the same except for one thing. You just add the aliases to .zshrc instead of .bashrc.