1

I want to execute a text file, but I need to change the file preferences so that when I open it, it will actually run the file instead displaying it. However, I don't know how to change the file preferences.

kiri
  • 28,246
  • 16
  • 81
  • 118
user249390
  • 11
  • 2

2 Answers2

0

I think the command you are looking for is bash. Here's a link and example:

cd /home/username/Documents
touch runafile
gedit runafile

#!/bin/bash (hit Enter to go down one line)
echo "Hello world"

(type Ctrl-x to exit)
(type y for yes)
(hit Enter to keep the filename)

bash runafile

By default in Ubuntu, a plain text file executes by opening in gedit (you can change this by right-clicking the text file/Properties/Open With). Are you attempting to execute a script? You can execute any file from terminal like this:

cd /desired/path
./fileToExecute
musicman1979
  • 1,147
  • 1
  • 9
  • 26
0

If you are looking to do this through Nautilus (called "File Browser" in recent versions, I think), you can mark a file as executable via the Properties dialog. Right-click on a file, go to Properties, then the Permissions tab, and check "Allow executing file as program".

(You can also set this via the chmod command – chmod u+x file.txt should do the trick.)

If you try to open it now, you'll be asked:

Do you want to run "file.txt", or display its contents?

"file.txt" is an executable text file.

[Run in Terminal] [Display] [Cancel] [Run]

Display will open it however the system would if it weren't executable. Run in Terminal will open a terminal and run it, printing out the normal output. Run will run it, without opening a terminal. Cancel cancels.

That should do the trick, I think.