how to make your own command in linux

How To Create and Run Your Own Command on Linux

Hi Friends today our topic is “How To Create and Run Your Own Command on Linux”

To create own command please use below steps: 

Linux operating system allows users to create commands and execute them over the command line. To create a command in Linux,the first step is to create a bash script for the command. The second step is to make the command executable.The script can be run only after file permissions have been changed to executable mode. Once changed, copy it to the binary path of Linux so that it can be run just like system-defined commands of operating systems. Follow these easy steps to create a command in Linux. 

Step 1:- First step to create bash file which will run your command on command line. Open vim or any editor, and type following code on file,

[root@server raj]# vim file-name


 echo “this is my first chance to create my own command'”     

 #then the rest of the files     

 echo “files of current directory are”


:wq (Save & Quit )

Give the file name as same as Command name you want to create, save this file.

Step2:- Now, you have to make this file executable. To make it executable use chmod command with option +x. CHMOD command is basically used to give access permission of files to user accounts. For more information about chmod command, open your terminal and type man chmod, you will get all information about chmod.

(Example for making file executable)

[root@server raj]# chmod +x  filel-name

Step3:- Now you have to copy this executable file to binary path of Linux that is “/usr/bin/”.
[root@server raj]# cp -rvf file-name /usr/bin

Sometimes for sudo (super user do) account user, it will not give you permission to copy this file to binary path of Linux. So to solve this we have to switch our account to root account, for this just type su command on terminal, it will asked you the current account password (only if you don’t created root account else you have to give root account password). After switching to root account copy your file into binary path that is “/usr/bin/”.

Now, try to execute your command, you can modify bash scripting file as per your requirement but you should have some basic knowledge of shell scripting to make perfect command that you want to create.

[root@server raj]# file-name

How To Create and Run Your Own Command on Linux

Tags: How To Create and Run Your Own Command on Linux,how to create your own run command,how to make your own cmd,how to make your own command in linux,how to create our own command in linux

Leave a Reply

Your email address will not be published. Required fields are marked *