I have shell script for monitoring local area traffic for my system. Now I want to install it, and want to run like other unix command

  • I think we'll need more details. You want to install from a script, or run a script?
    – philshem
    Nov 27, 2012 at 0:58
  • I need an idea about it. So I can do it myself
    – ADR
    Nov 27, 2012 at 1:06

3 Answers 3


The usual location to install local scripts is /usr/local/bin or /usr/local/sbin. See man hier for details of the directory structure.

These directories are usually included if the corresponding /usr/bin or /usr/sbin directories are in the path. See man eviron for information on the standard environment variables including PATH.

The directory hierarchy for many distributions is document in the heir man page. It can be displayed with the command man heir

/usr/local/bin is for programs that all users should be able to run. It is equivalent to /bin and /usr/bin. Normally, most users will not have these on their path.

/usr/local/sbin is for programs that are used for system administration. It is equivalent to /sbin and /usr/sbin.

  • 1
    Much easier than editing a config file. Just copy your script-file to /usr/local/bin or /usr/local/sbin, and you can immediately execute from a command-line.
    – johny why
    Aug 25, 2015 at 15:51
  • When should I use which?
    – Asqiir
    Jun 10, 2018 at 12:49
  • @Asqiir I've updated my response.
    – BillThor
    Jun 12, 2018 at 4:51
  • @Asqiir Sorry, but I couldn't resist: unix.stackexchange.com/q/85249/70524
    – muru
    Jun 12, 2018 at 5:02

The way I would solve this (with my fairly rudimentary linux skillz) is to make an alias to the shell script.

First ensure the shell script is executable.

chmod u+x,g+x script.sh

Then, edit your .bashrc file like following:

vi .bashrc

Add this towards the bottom. (I think you can also add this in a specific alias file, such as .bash_aliases, but I don't.)

alias commandtorun='/home/user/script.sh'

Here, commandtorun will be the command you type in to run the script, and '/home/user/script.sh' is the path to the script.

To save changes to your .bashrc in vi editor, :wq, which writes to file and quits.

Edit: You'll also need to re-source your .bashrc to use the changes in the current session. (Or just restart the session / close and reopen the terminal).

source ~/.bashrc

Good luck!

  • 4
    I would (personally) not create the alias and instead put the file in $HOME/bin. Creating an alias for every script is going to be hard to maintain if you create a lot of them. Also the chmod command would be a lot better off if it were either chmod +x script.sh or chmod a+x script.sh There should be no other users in your "user" group so the o+x option is kinda pointless. If you want others to be able to execute the file you need to either chown user:group script.sh and make sure that the "other users" are in that group. Or just let everyone execute it with chmod a+x script.sh
    – coteyr
    Nov 28, 2012 at 2:25
  • 2
    Also.... For scripts to be run system wide the convention is to put them in /usr/local/bin/. Scripts that are in your $HOME may not b visible to everyone else.
    – coteyr
    Nov 28, 2012 at 2:26
  • I had to log out and log in again for this to work on Ubuntu. And ultimately preferred user76204's solution. Mar 3, 2018 at 6:47
  • @AndriyMakukha You will need to re-load the .bashrc (see my edit at the end). Thanks for the suggestion.
    – David_G
    Mar 6, 2018 at 7:01

On Ubuntu, it is possible to create a bin folder in your home folder and place your user scripts in there. Indeed, your ~/.profile will contain the following:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

After you have created your bin folder you must logout and login again for /home/$USER/bin to appear in your path when you enter echo $PATH. Once it is in your path you will be able to call scripts in there by name and execute them just like you can any other programs.

The bin folder does not need any special permissions, and if you just want your user to be able to execute the scripts enter chmod u+x when you make them executable.

Your new output of echo $PATH when your bin folder is added should be:


You can place your scripts in /usr/local/bin, but you will need to use sudo to copy them to the folder and then use sudo again when you want to edit them there, so I find having a bin folder in the home folder is very convenient and sensible, particularly on a single user system.

However, it is important to note that if you have more than one user on your system and you want the script to be available for them all, you would definitely need to put it in /usr/local/bin.

Not the answer you're looking for? Browse other questions tagged or ask your own question.