There are commands that a Linux user uses more often. Some of these commands are long and some of them hard to remember.
Fortunately, there is a very simple way that Linux users can create custom commands and use them on their systems.
In the rest of this article, you will see how we can create bash custom commands and use them on Linux distros like Debian and Ubuntu.
The commands we are about to create will be written in a file named
.bashrc. This file needs to be located in Home directory.
Open the terminal and make sure you’re in the Home directory and then list the files and folders to see if the
.bashrc file already exists. You can do both by typing this command:
cd && ls
If you see the file, simply open it with an editor to work on it. If the file doesn’t exist in the Home directory, we need to create it first. The command below opens the existing file with the Nano editor. Also, if the file doesn’t exist, this command will it and open the blank file.
$ sudo nano .bashrc
The rest is very simple. We just choose a keyword for each command and write them in the following format:
Replace KEYWORD with the string that you want the command to be executed with, and replace COMMAND with the actual command. For example if you want the command
sudo apt update to be executed when you just type
update in the command line, you need to write the alias this way:
alias update='sudo apt update'
You can add as many aliases as needed. There is no limitation in creating custom commands in
.bashrc. Just don’t forget to write each alias in a new line.
When you finished editing the file, press Ctrl+O and then Enter to save changes, and finally exit the file with Ctrl+X
Now, you will be able to execute Linux commands just by typing the aliases that you have chosen for each of them in
.bashrc file is a hidden file and by default you won’t find it visible when browsing the Home directory with file explorers like Nautilus. If you wanted to check the file in Nautilus, press
Ctrl+H. Pressing this shortcut again will make it hidden too.
This is how we create a Linux user custom command. Hope this article has been helpful and bale to save you some time.
If you found this article helpful, support this blog by informing your mates and friends about this page and make sure to check other articles.