Using the command line seems rugged and unpleasant, but Linux has a way to ease things up and help you get things done with the command line by allowing you to use aliases to customize how you type commands.
Setting up Aliases
Aliases are a way for you to customize the commands by giving them aliases (nicknames). You can use them to remember hard commands or make short names to long commands you just hate to type. To setup aliases, right-click and create an empty file in your home directory and name it “.bash_aliases”. Notice the period at the beginning of the name that will make the file hidden. Press “Ctrl+H” to show the hidden files.
Using your favorite text editor open the file you just created and start making your aliases. But there are few things you should keep in mind, the syntax should be:
Where “new_name” is the alias, and “old_command” is the command you want to change and is put between quotes. Example:
alias agi='sudo apt-get install'
This will make typing “agi” the same as typing “sudo apt-get install”. This way if you have a dozen of packages to install, your task just got easier. Keep in mind that if you create an alias that looks the same as a command, then the command or alias will not work. Example:
alias install='sudo apt-get install'
The alias in the above example won’t work because there is already a command by the name “install”.
And remember that creating aliases from two words won’t work unless you connect them with a dash. Example:
alias apt install='sudo apt-get install'
alias apt-install='sudo apt-get install'
In the above example, the first alias is invalid as the alias consists of two separate words while the second alias is good to use because the two words are connected with a dash. And the last thing that you shouldn’t do is put any space at the starting of any line. So that’s everything about creating the aliases, but what aliases would you use? Keep reading!
What aliases to use
Now that you know how to setup aliases and create your own. Let’s see what aliases you can use to make the most out of it.
- Manage packages
If you have to install and remove packages too often then you really are going to like this.
alias agi='sudo apt-get install'
alias agr='sudo apt-get remove'
alias agu='sudo apt-get update'
alias acs='apt-cache search'
The aliases above are made of the first letters of each word in the command. These are just examples of what you can use and you can use them, modify them or create your own.
- Manage files and folders
alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -i'
alias la='ls -alh'
These aliases will make the command line ask you for confirmation on deleting files or overwriting them (if there were duplicates) when copying or moving files as well as give you more information on what is being done. This can prevent you from accidentally overwriting your files or sending them to somewhere you shouldn’t send them to.
- Navigating the system
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
alias desktop='cd ~/Desktop'
alias music='cd ~/Music'
alias videos='cd ~/Videos'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
Now navigating your files and folders can be no easier. Type the directory you want to go to and type dots to go up.
- Other useful aliases
alias shutdown='sudo shutdown –h now' #requires root password, disable it by "sudo chmod u+s /sbin/shutdown"
alias restart='sudo shutdown –r now' #requires root password, disable it by "sudo chmod u+s /sbin/shutdown"
alias suspend='sudo pm-suspend'
alias lock='gnome-screensaver-command --lock'
alias mounted='mount | column –t
Got any more tips or great aliases? Share them in the comments.