Create alias for shell commands in linux

Sometimes we need to type the same command many times in a terminal. One option would be looking for it in the terminal history which is handy but if we used the command a long time ago, it could be hard to find. So I recommend to use alias instead.

Take a look at the following command for connecting to an external MySQL database:

mysql -hMY_HOST.com -uDB_USER -pDB_PASSWORD -A DB_NAME

To create an alias for this command we only need to edit the “/etc/.bashrc” file

sudo nano /etc/.bashrc

and add the following

alias db1='mysql -hMY_HOST.com -uDB_NAME -pDB_PASSWORD -A DB_USER'

Reopen the terminal and try to use the new alias

db1

That’s it! we got the same result just writing 3 letters.

Remember that you can create an alias for any shell command you need.

Leave a Reply

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