Enter your email address below and subscribe to our newsletter

How to Make a File Executable in Linux

Learn how to make a file executable in Linux via 4 simple ways, even without terminal.

Share your love

When you want to execute a script or an AppImage, the file must have executable permissions. While it should complex, it is not and requires a single command to make a file executable.

The easiest way to make a file executable is to use the chmod command with the +x flag as shown here:

chmod +x Filename

Once you make the file executable, it can be executed by appending ./ to the filename as shown here:

./filename.sh

But there are other methods with more options and flexibility and in this tutorial, I will walk you through 4 ways you can make a file executable in Linux:

  1. Making files executable for everyone (recommended)
  2. Making files executable for certain groups
  3. Using octal numbers
  4. Using GUI (does not require terminal)

But before we get started, let’s take a look at some basics of file permissions which will be helpful to understand if the file is executable or not.

How to know if a file is executable or not?

To know if the file is executable or not, you’d have to check the file permissions. To do so, you’d have to use the getfacl command as shown here:

getfacl Filename

For example, if I want to check the file permissions for the Hello.txt file, then I’d use the getfacl command in the following manner:

getfacl Hello.txt
Check file permissions in Linux

The getfacl commands print permissions for user, group and others and as you can see, the user and group have read/write permissions whereas others are left with read-only.

Now, let’s take a look at how to add execution permissions.

Make the file executable for everyone

When you make a file executable for everyone, all the logged-in users can execute that particular file. And to do so, you use the chmod command with the +x flag.

Here, the x is used to add/remove execution permission to a file and when you append a + sign, you are instructing a system to add execution permissions. Here’s a syntax:

chmod +x Filename

For example, if I want to make the file Script.sh executable, then I’d use the following command:

chmod +x Script.sh
Make file executable for everyone

As you can see, it added execution permission for everyone.

Make file executable for a specific group

Making files executable for everyone might not be a good idea, especially if there are multiple users assigned to a single computer. For those times, you can add permissions to a specific group.

To make a file executable for a specific group or a user, you need to use classes while executing the chmod command. Here are the available classes for the chmod command:

  • u : permissions for owner/user.
  • g : permissions for group.
  • o : permissions for others.
  • a : permissions for everyone.

Here’s a syntax that you need to follow to specify classes while using the chmod command:

chmod <class>+x Filename

For example, if I want to add execution permission for a group, then I will use the following:

chmod g+x Script.sh
Add executution permission for group in linux

As you can see, it added execution permission for the group.

Make the file executable using octal numbers

Using octal numbers is more of an advanced way to specify file permissions. Using octal numbers, you can be more selective with what permissions you want to assign to a user, a group or others.

Octal is a number which represents a set of permissions ranging from 0 to 7. Here’s a table for your reference:

Octal ValuePermissionDescription
0No permissions
1–xExecute only
2-w-Write only
3-wxWrite and execute
4r–Read only
5r-xRead and execute
6rw-Read and write
7rwxRead, write, and execute

You are supposed to specify octal for user, group and others in a sequence. This means you will be using a 3-digit number where the first digit represents the user, the second digit is for the group and the third one is for others.

So if I use 754, it means:

  • 7 allows the user to read, write and execute
  • 5 allows group members to read and execute
  • 4 will restrict others to read-only

Now, let’s take a practical example.

If I want to set permission where the user can read, write and execute whereas the group and others can only read, then I will use the following:

chmod 744 Script.sh
Make file executable using octal numbers

Make file executable without terminal

If you are not comfortable using the terminal, then this method will allow you to make the file executable without executing a single command in the terminal.

I find it useful when I want to run an AppImage as soon as possible.

To make a file executable without a terminal, first open your file manager and then switch to a directory where the target file is located.

Now, right-click on the file and choose the Properties option, go to the Permissions tab and check the Allow executing file as program option as shown here:

Make file executable without terminal

Once you make a file file executable, you can run it by pressing the enter key but if it is a script, then you have to open a terminal to execute it.

Wrapping Up…

In this tutorial, I went through four ways how you can make a file executable in Linux. Each method has its own advantage. Personally, I use the first method a lot as I don’t share my computer with other users.

Let me know what method you guys would use to make a file executable. Also, if you have a recommendation on what should we cover next, then please leave us a comment.

Share your love
Kabir
Kabir

A tech journalist whose life revolves around networks.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!