Ubuntu is a Linux distribution that comes with a lot of built-in commands. However, there are also a lot of third-party applications that you can install and use. To make life easier, you can use aliases to customize these commands. To create an alias for the ls command, type the following command: alias ls=‘ls -l’ This will create an alias for the ls command that will list all files in the current directory. You can then use this alias to customize the ls command by adding specific files to it or changing its output. For example, if you want to list all files in the current directory but not show their names, you could add this line to your ~/.bashrc file: alias ls=‘ls -l | grep “^name” | cut -d’ -f1’
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.
Aliases Syntax
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:
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:
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:
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!
alias apt-install=‘sudo apt-get install’
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.
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.
alias agr=‘sudo apt-get remove’
alias agu=‘sudo apt-get update’
alias acs=‘apt-cache search’
Manage files and folders
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.
alias mv=‘mv -iv’
alias rm=‘rm -i’
alias la=‘ls -alh’
Navigating the system
Now navigating your files and folders can be no easier. Type the directory you want to go to and type dots to go up.
alias downloads=‘cd ~/Downloads’
alias desktop=‘cd ~/Desktop’
alias music=‘cd ~/Music’
alias videos=‘cd ~/Videos’
alias ..=‘cd ..’
alias …=‘cd ../..’
alias ….=‘cd ../../..’
Other useful aliases
alias s=‘sudo’
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.