DEV Community

Alexander Omorokunwa
Alexander Omorokunwa

Posted on • Originally published at on

How to Create Your Own Linux Commands


Who does not like to have the power to create things? Among many powers, Linux gives you the ability to create commands; or wrap default Linux commands in any new command of your choice.

Actually you will not be creating new commands (like “cat”, “ls” or “touch” ) that could be used on any Linux distribution (distro) out there. Far from it. \ **Winks*. Instead you can create some command aliases (or you could say alternate commands) on your local system for personal use – using the Linux **alias* command.

This is especially useful when you have to type long commands; which can become tiring when you have to do this on a regular basis. It can also be useful in helping you putting commands in words that are memorable.

Without much ado lets dive right in.


Add a file called “.bash_aliases” (create if it doesn’t exist) in your home directory (/user/home).


Then add any command alias (alternate commands) you want in the general form:

alias command_alias = “actual command”

and then save the file.

Where the “actual_command” is the command to be executed when when the “command_alias” (the new name you have given it) is typed into the command-line.


>> If the “.bash_aliases” file does not exist create it:

touch .bash_aliases

>> Add the “ sudo /etc/init.d/apache2 start” command as an alias in the file:

alias apacheon = sudo /etc/init.d/apache2 start”

>> Save the file.

The new command alias “ apacheon ” is mapped to the actual command ( sudo /etc/init.d/apache2 start ). This means that any time you enter “ apacheon ” in the terminal it is interpreted by bash to mean “ sudo /etc/init.d/apache2 start ”, which is then executed.

You can add as many aliases as you wish/need in the file.


alias apachestop = “/etc/init.d/apache2 stop”

alias systemupdate = “sudo apt-get -y update”

alias wscan = “sudo iwlist wlan0 scan | more”

Try your hands on a few aliases to see for yourself!!!

Happy Linux’NG!

The post How to Create Your Own Linux Commands appeared first on Foss Naija.

Top comments (0)