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

Whenever I open a .sh file, it opens it in gedit instead of the terminal. I can't find any option similar to Right ClickOpen WithOther Application...Terminal.

How do I open this file in the terminal?

share|improve this question
Does that script aim to set up env variables for further use? – Rob May 1 '11 at 10:47
You shouldn't use extensions on scripts. At some point in the future, you may find that a different language is more suitable to do the task your current script is doing. And then you have a problem. Do you keep the old name, with a completely misleading extension, or do you rename it, possibly having to edit alot of places where your script is used? – geirha May 1 '11 at 14:07
You don't need the file extension. It's nice to have but is not needed. The OS doesn't look at the file extension. It looks at the data – ActionParsnip May 4 '11 at 17:41
Meh, if you rewrite in ruby, you can always use the .sh file to launch ruby foo.rb – glenn jackman Jun 11 '13 at 1:24
In Dolphin you can press F4 and a console opens – Motte001 Jun 16 at 16:47

11 Answers 11

Give execute permission to your script:

chmod +x /path/to/

And to run your script:


Since . refers to the current directory: if is in the current directory, you can simplify this to:

share|improve this answer
+1 only answer to show adding execute permissions in a terminal only way. – Hailwood May 1 '11 at 3:24
If you do bash /path/to/ then you don't need chmod +x – Aleksandr Levchuk May 1 '11 at 4:51
Actually, you can use . /path/to/ if the script have to set up some environment variables. – Rob May 1 '11 at 10:46
Nobody mentions the traditional: ./path/to/ (without the space after .)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as ./ would, though I don't see why you wouldn't use ./: (FILENAME=~/;SLL=$(cat $FILENAME|head -1|sed 's:^#!\(.*\):\1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME) ... edit FILENAME to your liking. Also note that sh will be used if there is no alternative. – MiJyn Jun 19 '13 at 3:50

You need to mark shell scripts as executable to run them from the file manager:

  1. Right click on your .sh file and select Properties:

    enter image description here

  2. In the Permissions tab, check Allow executing file as program:

    enter image description here

  3. Close the Properties window and double-click the file. A dialog will pop up giving you the option to run the script in a terminal:

    enter image description here

share|improve this answer
Good w/ screenshots – gd1 May 1 '11 at 9:32
+1, a very nice answer indeed. – sukhbir May 1 '11 at 12:10
+1 for GUI explanation and screenshots – bruno077 May 4 '11 at 19:55
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this. – mpen Jul 12 '13 at 16:27


Before you can run the .sh file, you need to make it executable:

  1. Right-click on the file
  2. Select Properties
  3. Select Permissions
  4. Select Allow executing file as a program


Make sure you trust the source where you got the file from. It could be a virus.

The very simple way

  1. Double-click on the file
  2. Click run in terminal

This has problem. The terminal will close immediately and you will not be able to see the output.

The simple way

  1. Open Applications -> Accessories -> Terminal
  2. Drag and drop the .sh file into the terminal and press Enter

The way professionals do it

  1. Open Applications -> Accessories -> Terminal
  2. Find where the .sh file

    • Use the ls and cd commands
    • ls will list the files and folders in the current folder. Give it a try: type "ls" and press Enter.
    • Once you see the folder that you want to go in to, run cd, followed by a space, followed by a folder name
    • If you when into a folder that you did not want, run cd .. to go one level up
  3. Run the .sh file

    • Once you can see for example with ls run this:


Why do it the complicated way?

The terminal has a rich set of powerful tools that are accessible by typing the commands. Professionals locate the .sh file by typing ls and cd. Once you are in the correct current folder you can run the script like this:


or you can run and redirect the output to a file:

./ > out.txt

or you can filter the output for keywords (e.g. "apples") an then redirect to a file:

./ | grep apples > ./only-apples

There are thousands of things you can to to that file just by typing a few commands.

Another one, you can download a file from the Internet with one simple command:


And then open the file like this:

shotwell ps_logo2.png
share|improve this answer
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way – Hailwood May 1 '11 at 4:24

On Ubuntu 13.04 executable files opened in Nautilus are now opened in gedit by default rather than prompting the user to execute them. To enable the classic behavior you need to adjust the preferences:

Nautilus → Edit menu → Preferences → Behaviour tab → Click the radio button near Ask each time.

share|improve this answer
The person who asked the question is talking about Ubuntu 10.10 – edwin Jun 11 '13 at 0:48
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything. – mpen Jul 12 '13 at 16:28
This is the right answer for latest ubuntus. – gaRex Apr 11 '15 at 11:44
How do you get to Nautilus in 15.10? – Tricks for the Web May 23 at 17:54

Open a terminal and navigate to the folder where the .sh file is located. Then type:

sh <name of file>.sh
share|improve this answer
Why sudo? This is unrelated to the question and might have unwanted side effects. – gertvdijk Dec 20 '12 at 11:57
Unless necessary, you should avoid running commands as root. Doing so could allow a small bug in that script to have dangerous side effects (e.g. delete vital system files). Here's a related question: – Evan Teitelman Dec 27 '12 at 1:08
sh is just another type of shell (like bash). After @edwin 's edit (simply removing sudo) this is a fine answer IMO and the above two comments are obsolete. – nutty about natty Jun 15 '14 at 7:12

2 main steps.

  1. in terminal, use gedit to write and save script with ".sh" extension to desktop. (but any text editor can be used)

  2. open Nautilus and right click the file.

    • under properties, check box "allow executing file.."

    • in Nautilus menu, click file,then preferences,then behaviour

    • check the "run executable text files when they are opened".

Now, when you double click the file on the desktop, it should execute. no need for . or ./

share|improve this answer

If you place your shell script or other executable you create in /usr/local/bin it will be found and executed without having to provide a folder path in the command line or adding ./ to the name. For example I created the following simple 3 line bash script to display disk UUIDs:

echo "* UUIDs must match in /etc/fstab and /boot/grub/menu.lst"
sudo blkid

I called the file uuid and placed it in /usr/local/bin. All I need enter on the command line is:

share|improve this answer

There are a few ways to do this.

Option 1

1) In the terminal, access the directory the Bash file is in using cd (change directory).

Ex. cd Downloads

2) Run bash <filename>.sh

This also works with .run files. There is an example of this usage at this webpage on updating Rhythmbox.

Option 2

1) In the terminal, navigate to the directory the bash file is in.

2) Run chmod +x <filename>.sh

3) In Nautilus, open the file.

share|improve this answer

The problem i have found on a few distributions is they have hidden the preferences option in nautilus... but to fix it in both ubuntu and other distributions using gnome3 is the same (literally just done the fedora version of this and posting the actual fix to remind me how in the future)

1) install dconf-editor

sudo apt-get install dconf-editor

2) run dconf-editor using the user account you want this on.. i.e NOT root


3) navigate to the following location

org > gnome > nautilus > preferences

4) change the default option to not open by default

find "executable-text-activation" click the word "display" and change to "ask"

that will give you the option to edit, view or run the file going forward

share|improve this answer

You can also use . tricks, with the suggestion of other answers.

For example:

chmod +x, assuming you have already gone to the path to file then run the file with any one of these command:



share|improve this answer

Well, I too faced the same problem. I wanted to execute the .sh file and it opened with Gedit on CentOS 7. So here is what I did:

  1. I navigated to the path of the .sh file I wanted to execute.
  2. I opened the terminal.
  3. And I simply dragged and dropped the on the terminal window and it automatically took that file along with the path as input.
  4. Hit Enter and you are good to go!
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.