Create Your Own Custom Linux Command

linux custom command

Have you ever dreamed of having a Linux command that did that thing you wanted to do in 1 line? Or maybe you need to repeat a command with some specific parameters periodically and see the output on your console to check what is going on in a specific part of the system while recording the output in a log file?

No matter the specific scenario, at some point you will like to have your own custom Linux command if you are spending a considerable amount of time on Linux boxes repeating some tasks. Here is how you can create your own custom Linux command:

1- Create a file under “/username/bin” (don’t specify any extensions in your file name)

2- Below should be the first line of your script file

3- Add the command or commands you want to run in your script file. Example:

4- Change the mod of your file to make it an executable

5- Reload bashrc

Now you command should be working. The example command above can be used like this:

This example command will run “oc get nodes” every 30 seconds (I named my custom command file as “repeat“).

 

Hope this helps.

Good Luck,

Serdar