Linux - Create your own command

October 2017

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.


Below are the steps to create your own command on Linux.

Creating a Bash script

The first step is to create a Bash script which will run your command.


#on displays the actual folder name      
echo "the folder is 'pwd'"      

#then the rest of the files      
echo "The folder which contains files are 'ls'"
  • Save this file (CTRL + O with Nano) give it the name of your command (Example: FileInfos).

Make the command executable

  • Try to type the name of your bash script, you will notice that it will be executed (run).
  • Now you have to modify the CHMOD of the script which you will run by typing:
    • chmod +x yourScript
  • Now, copy your script in the path, /usr/bin like below:
    • cp yourscript /usr/bin/
  • Now you are done! Run your command by typing the script name which you moved in /usr/bin.
Published by hyts78. Latest update on February 9, 2012 at 08:32 AM by Paul Berentzen.
This document, titled "Linux - Create your own command ," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (