I created a .sh (or bash) file and I would like to make a command in GNOME-Terminal for the file. I know you run a .sh file by:


After you compile it, I also know all the command are stored in /bin/bash. But I can't seem to figure out how I can create a command that I can call when I am in any directory in the terminal, something like:


would run abc.h, etc. Any suggestions?


Although Radu's answer is absolutely correct, I feel like it's a bit incomplete for the beginner that does not know the location of certain files, so here's a step-by-step on the second method (using ~/bin). If you would like to store the files somewhere else than ~/bin, follow step 1, otherwise, ignore it and keep in mind you'll be using ~/bin as your scripts folders.

  1. Open a terminal and run the following:

    nano .profile

    You should see, at the end of the file:

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

    If you don't see it, try using nano .bash_profile instead. Keep in mind you should be at ~/, that is, /home/YOUR_USERNAME

    This tells bash where user's scripts are. The default is /home/YOUR_USERNAME/bin which is "abbreviated" as $HOME/bin or ~/bin. You can then change it to any folder you'd like to store your scripts in. Mine is ~/.bin -- the same as the original, but hidden.

  2. If you already issued chmod +x script.sh just move your scripts to the folder in which you're going to store them - create it if it doesn't exist. Inside that folder, if you store your scripts as file.sh you'll have to run file.sh everytime, so store them as file -- no extensions.

  • I cant seem to move any file into the File System directory, any suggestions on how I can disable this setting?
    – 0101011
    Apr 27 '13 at 0:16
  • I'm sorry, I don't understand your question. Can you rephrase it?
    – Alex
    Apr 27 '13 at 0:37
  • 1
    Yeah, I can't move the file to the /bin directory, because it blocks me off. BUT I figured it out sudo mv file /bin, thanks though
    – 0101011
    Apr 27 '13 at 0:42
  • 1
    @01100011_0101011_0101011 He was referring to /home/$USER/bin (~/bin), not /bin; you should put your user scripts in that folder in your home folder, not in /bin.
    – user76204
    Apr 28 '13 at 10:58

The shell maintains a list of directories where executable files (programs) are kept, and just searches the directories in that list. If it does not find the program after searching each directory in the list, it will issue the famous command not found error message. This list of directories is called your path. You can view the list of directories with the following command:

echo $PATH

You can add directories to your path with the following command, where *directory* is the name of the directory you want to add:

export PATH=$PATH:*directory*

A better way would be to edit your .bash_profile file to include the above command. That way, it would be done automatically every time you log in.

Most modern Linux distributions encourage a practice in which each user has a specific directory for the programs he personally uses. This directory is called bin and is a subdirectory of your home directory. If you do not already have one, create it with the following command:

mkdir bin

Move your script into your new bin directory and you're all set. Now you just have to type:


and your script will run.


I would recommend alias function instead. The other approaches does work, but they do not get rid of the ".sh" extension as you wanted.

It can also mess with path system if you forgot to add ${PATH}: into the export PATH.

you can type:

alias test="/your/path/to/file/test.sh"

If it is working properly, you need to add it into your .bashrc file:

sudo gedit ~/.bashrc copy your alias command at the end of the file.

or a faster way (needs attention):

echo "alias test=/path/to/folder/text.sh" >> .bashrc

Just please don't forget to use >>, if only > was employed it will replate the entire file with only the echo command.

and finally

source ~/.bashrc

to update the .bashrc commands.

Alias may be even more powerful since you can add some input options as e.g. below:

alias gaussview='XLIB_SKIP_ARGB_VISUALS=1 $GV_DIR/gview "$@"'

I hope you find it useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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