DEV Community

Alexander Omorokunwa
Alexander Omorokunwa

Posted on • Originally published at fossnaija.com on

10 3

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.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay