I’m going to kick off the Linux Toolbox with a relatively simple one.
Purpose: create command-line shortcuts
Benefit: save time and effort by simplifying complicated, commonly-executed commands.
If you spend any time at the Linux command-line, chances are that you are going to type the same commands repeatedly. Or, there may be long or complex commands that you enter only rarely, but you don’t want to have to look up every time you need them.
Alias allows you create temporary command shortcuts within the current terminal session.
The syntax* is fairly simple:
alias ll='ls -l'
This example would create the shortcut ll, which would execute the command ls -l and give you a listing of your current directory in the “long” format. simple stuff. And, since it’s temporary, once you initiate a new terminal session, typing ll will probably result in a command-not-found error.
You can also use alias to create a shortcut for a series of commands:
alias distup='sudo apt-get update; sudo apt-get dist-upgrade;'
This follows the bash syntax of separating multiple commands with a semi-colon, and gives you a single command to execute what would normally require much more typing. This particular alias is probably the command i use more than any other, as I tend to run the upgrade pretty much daily.
Alias is great by itself, but its usefulness really becomes apparent when combined with the .bashrc file, which handles the task of setting up your bash environment each time a session is initiated. In fact, if you look at your current ~/.bashrc file, you’ll probably find several aliases already setup. you can type alias as a command with no arguments, and it will return a list of all the aliases in your current session, including those established in the ~/.bashrc.
You could also store your “permanent” alias definitions in a separate file, for ease of management. If your distro’s ~/.bashrc doesn’t include this block of code, you can add it:
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
Then create the ~/.bash_aliases file, add your new aliases (one per line), and copy over any existing aliases from ~/.bashrc.
Once you’ve added your new aliases, each new bash session you initiate will have your aliases setup and ready to run.
To activate them in the current session, reload your bash settings:
The major limitation of alias is the inability to create an alias using variables to pass arguments to the aliased command. while this does restrict some possible usages, it doesn’t negate the command’s ultimate utility.
Alias can be a huge relief for frequent command-line users, helping to simplify tedious commands, speed up entry, or make commands more easy to remember.
Every user has their own way of setting things up, of course. What command would you consider, like alias to be indispensable in your daily usage? If you’re already making good use of alias, what are your favorite or most used aliases?
Here are some of mine:
# retrieve and install launchpad PPA key to synaptics keyring
alias addlpkey='sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com'
# cleanup synaptics packages
alias apclean='sudo apt-get autoclean; sudo apt-get autoremove'
# quick synaptics package install shortcut
alias apinst='sudo apt-get install'
# call exirename for ALL JPEG images in directory
alias exiren='exirename *.jpg; exirename *.JPG'
# send a task description to an inbox file
alias in='echo >> /home/username/inbox.txt'
# quick shortcut to launch a common ssh session
alias ssh01='ssh 255.255.255.1 -p 25'
# edit a file as root, useful for system administration
alias svim='sudo vim'