Friday, February 1, 2013

CREATE AND RUN YOUR OWN COMMAND ON LINUX

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. Sometimes we need multiple commands to fulfill our desire task but it’s not flexible for user to execute all bunches of commands every time, so we can combine them together   and after that we can form our own command. 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 GEDIT, and type following code on file,

   #!/bin/bash         
   echo "this is my first chance to create my own command'"     
   #then the rest of the files     
   echo "files of current directory are"
   ls

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)

    chmod +x filelist  ( filelist is name of file )

Step3:- Now you have to copy this executable file to binary path of Linux that is “/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.

3 comments:

  1. Please send this as your trick to "Linux for You".

    ReplyDelete
  2. @tushar kute: sir, linuxfor u administrators accepts only the tricks which are not invented yet, n this trick is already available on the internet i m here by attaching the link from where he took the referrence. check the date of both post... n u will know.THanks
    root@bt: # sumit dewang
    root@bt: shutdown -s now


    http://askubuntu.com/questions/131341/can-i-make-my-own-commands

    ReplyDelete