How to Create and Use Alias in Linux

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

$  alias

list-aliases
list-aliases

Now you can see executing:

$  ll

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”

custom-alias
custom-alias

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  admin@192.168.1.133″
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.

74 Replies to “How to Create and Use Alias in Linux”

  1. Good day! tecpenguin.com

    We suggesting

    Sending your commercial offer through the feedback form which can be found on the sites in the Communication section. Contact form are filled in by our application and the captcha is solved. The superiority of this method is that messages sent through feedback forms are whitelisted. This method raise the chances that your message will be open.

    Our database contains more than 25 million sites around the world to which we can send your message.

    The cost of one million messages 49 USD

    FREE TEST mailing of 50,000 messages to any country of your choice.

    This message is automatically generated to use our contacts for communication.

    Contact us.
    Telegram – @FeedbackFormEU
    Skype FeedbackForm2019
    Email – FeedbackForm@make-success.com
    WhatsApp – +44 7598 509161

Leave a Reply

Your email address will not be published. Required fields are marked *