How to Create Your Own Linux Commands

By | October 15, 2018

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.

 

READ  Extern OS: the Linux you wish you had

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!

Share!

ALEXANDER WAYNE OMOROKUNWA

ALEXANDER WAYNE OMOROKUNWA

Chief Editor/Founder at FossNaija
A Linux enthusiast with a focus on enriching the Nigeria Linux experience and keeping a keen eye on Ubuntu and other Foss related developments.
ALEXANDER WAYNE OMOROKUNWA

Latest posts by ALEXANDER WAYNE OMOROKUNWA (see all)

Tell us what you think

This site uses Akismet to reduce spam. Learn how your comment data is processed.