DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Alexander Omorokunwa
Alexander Omorokunwa

Posted on • Originally published at fossnaija.com on

How to Create Your Own Linux Commands

linux_alias_command_banner

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.

STEP 1:

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

STEP 2:

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.

Example:

>> 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.

Examples:

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)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.