Defining a shortcut with the alias command in Linux

Defining a shortcut with the alias command in Linux

January 16, 2024·İbrahim Korucuoğlu
İbrahim Korucuoğlu

In the Linux command line, you can define abbreviations for commands that you use frequently and that are long to type. Thanks to the abbreviation you define, you shorten long commands and save time. In this article, the use of the alias command and creating abbreviations will be explained.

alias uptodate='sudo apt update && sudo apt upgrade'

Thanks to the update command given above, a long command has been converted into an abbreviation of uptodate. It is possible to multiply these examples. For example, let’s shorten the systemctl command to view the services running on our system.

alias active_services='systemctl --type=service --state=running'

You need to make these commands and similar ones permanent. If you want to use alias abbreviations when your system restarts, you must create a file named .bash_aliases in the home folder. You can add any abbreviations you want into this file, one command per line. Below is the screenshot of the file we created.

nano .bash_aliases
nano editor .bash_aliases

We can save the file with the Ctrl+o keys and exit with the Ctrl+x key. Finally, since the file needs to be reloaded into the system, let’s restart the bash software with the following command. Now, when you type active and press the Tab key, it will auto-complete and the abbreviation will work.

linux@rpi4:~ $ source .bashrc
linux@rpi4:~ $ active_services

In this way, your working speed on the command line will increase significantly.

Last updated on