Unlike Windows, Linux doesn’t typically care about file extension when determining whether something is executable. Instead, it looks at file system data known as inodes to make this decision. Because of this, you can make a file executable in any distro with nearly no restriction! Here are a few ways you can make a file executable in Linux.
1. Using The Command Line
To effectively manage file permissions on Linux, you should be at least somewhat familiar with the chmod
command. This handy tool allows you to quickly change the permission level of several files with numerical values and flags. For our purposes, we’ll just be using the +x
flag to make files executable.
The simplest way to use chmod
to make a file executable is to type it followed by +x
and the file’s absolute path:
chmod +x /path/to/file
Just like that, the file will become executable.
This will make the file executable for everyone, not just you. If you want to set a file as executable only for the account on the system that owns it, precede the flag with a u
:
chmod u+x /path/to/file
To make a file executable for the group that owns the file, use g
instead of u
:
chmod g+x /path/to/file
You can combine the two to make files executable for both the group and your current account in the system:
chmod ug+x /path/to/file
With the command line, you can also do some nifty things like specify a range of files:
chmod +x /path/to/file{0001..0008}
In case you don’t have a convenient numerical range in your file names, you can also specify each file in a separate argument:
chmod +x file1.sh file2.sh file3.sh
This is something that offers you more flexibility and as you familiarize yourself more with the Linux command line, you may find it easier to do some operations here than in a graphical environment.
2. Using a GUI
Since the Linux developer community offers us a plethora of file managers to choose from, it’s not feasible to showcase how to make a file executable in all of them. Instead, we’ll have a look at some of the most common file managers that come pre-packaged in the vast majority of distros:
Nemo
In Nemo, right-click the file you’d like to make executable and click “Properties.”
Go to the “Permissions” tab and tick the checkbox that says “Allow executing file as program.”
Click “Close” and it’s all done!
Nautilus/GNOME Files
Recently, Nautilus has been renamed to GNOME Files as it’s become the default file manager for all GNOME desktops. Unfortunately, the developers have made it impossible to change file permissions to execute custom shell scripts here.
You’ll have to use the terminal or an alternative file manager to make a file executable.
KDE Dolphin
To make a file executable in Dolphin, right-click on it and click “Properties.”
Once in, click on the “Permissions” tab and tick the checkbox that says “Make the file executable.”
Click “OK” and you’re done!
PCManFM
In PCManFM, the procedure is just a little different. Start, as usual, by right-clicking the file and clicking “Properties.”
Click on the “Permissions” tab and then select who you’d like this file to be executable for from the drop-down list. In most cases, selecting “Anyone” is just fine, though for security reasons you may want to select “Only owner” or “Only owner and group.”
After you’ve made your selection, click “OK” to confirm the changes.
Check Whether a File Is Executable
While in a GUI environment, it’s pretty obvious whether you’ve made a file executable or not. After all, you had to click a button with some visual feedback to get there. However, in a terminal environment, you might want to have a quick peek to see if you’ve done everything correctly.
The ls
command is immensely useful for this purpose. Use it on the path where the executable file should be and, with a little flag, we can find out if your magic worked.
ls -l
This tells the terminal to display a list of files in the “long” format, including all permissions, modification timestamps, ownership details, and size. We’re only interested in the permissions.
The output will look something like this:
The permissions will always show up to the very left of each line of the output, once for each file listed. It’s separated into 3 columns where the first is the owner’s permissions, the second is the group’s permissions, and the third is the permissions for everyone else.
r
is for read, w
is for write, and x
is for execute. If the x
shows up in the columns you intended it to show up in, you’ve successfully made your file executable!
Remove Execute Permissions from a File
To remove the execution permission from a file in a GUI, all you have to do is follow the instructions again for your specific file manager and untick the checkbox (Nemo, Dolphin) or select “Nobody” from the dropdown menu (PCManFM).
In the command line, all you have to do is substitute the +
for a -
in the commands we went through, for example:
chmod -x /path/to/file
Going Farther
If you’d like to make things a little more interesting and learn just how powerful the command line can be when setting file permissions, be sure to read our guide that shows you how to do this recursively across complex directory structures. If you’re a newer user, you may want to go through some basic bash commands first. You’ll find that the terminal isn’t really as scary as it seems!
Our latest tutorials delivered straight to your inbox