Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
I think we'll need more details. You want to install from a script, or run a script? – philshem Nov 27 '12 at 0:58
I need an idea about it. So I can do it myself – ADR Nov 27 '12 at 1:06
up vote 6 down vote accepted

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

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/'

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

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

Good luck!

share|improve this answer
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 or chmod a+x 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 and make sure that the "other users" are in that group. Or just let everyone execute it with chmod a+x – coteyr Nov 28 '12 at 2:25
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 '12 at 2:26

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.

share|improve this answer
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 '15 at 15:51

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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