Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Is there a way to make a file that would run a terminal command when you click it? Similar to a .bat extension in windows?

share|improve this question

3 Answers 3

up vote 23 down vote accepted

Open your text editor, and type the following line: #! /bin/bash. Leave an empty line and start typing your commands. Save the file, the extension doesn't matter. Go to the file in your file manager, right-click it, open the properties dialog, go to the permissions tab in the dialog, check the "Allow execution of this file", and click the close button. Now you can double-click the file and choose to run it in a terminal window.

share|improve this answer
Great! Thanks a lot! –  bmazoka Feb 22 '12 at 20:11
out of curiosity.. what did u use to record and post it to animate like that? –  bmazoka Feb 22 '12 at 20:24
Byzanz ;) If you watch closely you can see me minimizing a terminal window with byzanz-record at the beginning of the animation. –  RobinJ Feb 22 '12 at 20:28
+1, those animated gifs are pretty slick and make for a very good answer. –  psusi Feb 22 '12 at 21:07
byzanz cool !!!! –  wim Feb 23 '12 at 1:17

In Linux those are called scripts of more accurately shell scripts.

Linux does not care what extension the file, it will look at the file's permissions to find if the file is set as executable and will run it if so.

You can create a script with any favorite text editor, just open one up and start scripting, you can use any shell interpreter you want being the normal used ones bash and sh.

Normally you start your scripts by declaring which command interpreter you want to use, #!/bin/bash for bash and #!/bin/sh for sh. After you have done so you can start typing commands in to the script lines just as you do on Windows with batch scripts.

After you have done editing, save your file and make it executable.

You can either open a terminal and type chmod 755 foo (where foo is your script name) or right click on the file you just created and on the permissions tab click in the Make the file executable.

When you are done you can double click on the file and your file manager should try to run it or ask if you want to run it. As an alternative you can also invoke your script in a terminal changing dir to where your script is and invoking it with ./foo.

A good start to learn Linux shell scripting is LinuxCommand.org, they teach you what you need, how to do it and have a lot of good examples on scripts that you can have a look at.

share|improve this answer

If it is a simple, one-line command, you can create a .desktop file, for example for a straightforward copy command like (in its simpelest form):

[Desktop Entry]
Name=Simple Copy
Exec=/bin/bash -c 'cp <source> <destination>'

Put the command between quotes, save the file with a .desktop extension, make it executable and run it by double-click.

enter image description here

You can make a .desktop file more complicated, add options, keywords, set an icon etc.
See this link.

share|improve this answer

protected by Community Jun 25 at 7:47

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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