We all know that command line is fast, but Linux users often need to use the same command over and over again it slow you down and affects you productivity and also if the command is long you need to remember it and type it.
You can save some time by creating aliases for your most often used commands. Aliases are custom defined short commands.
List Currently Defined Aliases in Linux
Now you can see executing:
is actually executing:
$ ls -alF
Thus ll is just an alias to ls -alF
Creating Aliases in Linux
Creating an alias in Linux is very easy task there are two types of alias that you can create temporary or permanent.
Creating Temporary Alias in Linux
you can make use of alias command to create any alias with the following syntax.
$ alias shortcommand=”your long command”
for example /var/www/html is a directory where you store your code and you often need to cd to this path, you can create alias for this as follows.
$ alias wr=”cd /var/www/html”
But there is a problem with approach alias created this way it will only last for current session if you open new terminal session it will vanish. But there is a way to create permanent aliases.
Creating Permanent Aliases in Linux
To keep alias available for all sessions you can write the alias to users shell config profile file.
Bash – ~/.bashrc
ZSH – ~/.zshrc
Fish – ~/.config/fish/config.fish
The syntax to be used for creating permanent alias is same as for temporary one, the difference is that you will be saving the command in file this time. You can edit the file with your favorite editor.
$ vim ~/.bashrc
You can add the aliases in the end of the file as follows:
alias dev=”ssh ~/.ssh/pem-file.pem email@example.com″
alias wr=”cd /var/www/html”
Save the file and these aliases will be available in all your future sessions.
If you want these to become available for current session as well run following command.
$ source ~/.bashrc
To remove an alias that was added using command line you can use unalias command.
$ unalias alias_name
$ unalias -a (removes all alias)
Alias is a very useful feature it saves you time and keep from writing or remembering long command. Feel free to provide feedback and Let us know in the comments section how did you make use of alias.