> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Make a File Executable in Linux terminal?
- URL: https://linuxhandbook.com/make-file-executable/
- Published: 2022-02-17T10:01:00.000Z
- Updated: 2022-03-17T10:01:50.000Z
- Description: New to Linux command line and wondering how to make a bash script or some other file executable? Here's how to do it.
- Author: Abhishek Prakash
- Tags: Tips

Each file that is in a POSIX-compatible file system (Ext4, Btrfs, XFS, JFS etc) has "mode bits" assigned to itself.

To make a file executable in Linux, the executable mode bit needs to be enabled.

To set the executable mode bit, the [chmod command](https://linuxhandbook.com/chmod-command/) is used like this:

```bash
chmod u+x <file>
```

With that, you can execute said file from the terminal: 

```
./file
```

That was the quick summary. Let's see things a bit in detail.

## Make a file executable in Linux

There are several ways you can make a file executable in Linux. The most common methods involve using the `chmod` command, in different ways.

To check if you can execute a file, use the `-l` flag with `ls` command.

```bash
$ ls -l lhb.txt
-rw-r--r--  1 pratham  staff  0 Mar 10 20:49 lhb.txt
```

In the first column, `-rw-r--r--` represents that the owner can read and write, users from the group can only read and everyone else can only read the file.

Note the lack of `x` from the permission symbols. This means that `lhb.txt` is not executable.

![](https://linuxhandbook.com/content/images/2022/03/file-permission-explanation-2-1.png)

I highly recommend reading about [Linux file permissions](https://linuxhandbook.com/linux-file-permissions/) and brushing up your basics to better understand these commands.

[Linux File Permissions and Ownership Explained with ExamplesLinux file permissions explained in simpler terms. Also learn how to change the file permissions and ownership in Linux in this detailed beginner’s guide.![](https://linuxhandbook.com/favicon.png)Linux HandbookAbhishek Prakash![](https://linuxhandbook.com/content/images/2020/06/linux-file-permission-featured.jpeg)](https://linuxhandbook.com/linux-file-permissions/)

### Method 1: Make file executable for everyone

The first method, and the most straightforward one, is to make a file executable using the following command:

```bash
chmod +x <file>
```

The `x` flag is to set or unset the executable permission of a file. And using `+` sign before `x` means we want to set it as an executable file.

This will make the file executable for the owner, group and everyone else. Anyone on the system, will be able to execute it as well.

```bash
$ ls -l lhb.txt
-rw-r--r--  1 pratham  staff  0 Mar 10 20:49 lhb.txt

$ chmod +x lhb.txt

$ ls -l lhb.txt
-rwxr-xr-x  1 pratham  staff  0 Mar 10 20:49 lhb.txt
```

As you can see now, everyone, the owner, group and others have the executable `x` bit set. This means everyone can execute this file now.

### Method 2: Make file executable only for certain user or group

If you do not want to make everyone able to execute a file, you should specify classes before adding/removing file permissions.

The available classes are:

- `u` : permissions for owner/user
- `g` : permissions for group
- `o` : permissions for others
- `a` : permissions for everyone

When you specify a class, the syntax is mostly similar to the one you saw in the first method.

```bash
chmod <class>+x <file>
```

This means, if I want to make the file executable in a manner such that only the owner of the file can execute it, and no one else, then I should use the following command:

```
chmod u+x <file>
```

Here's an example:

```bash
$ ls -l lhb.txt
-rw-r--r--  1 pratham  staff  0 Mar 10 20:49 lhb.txt

$ chmod u+x lhb.txt

$ ls -l lhb.txt
-rwxr--r--  1 pratham  staff  0 Mar 10 20:49 lhb.txt
```

Similarly, to make it executable for everyone in the group owning that file, I should use the following command:

```
chmod g+x <file>
```

Here's an example:

```bash
$ ls -l lhb.txt
-rw-r--r--  1 pratham  staff  0 Mar 10 20:49 lhb.txt

$ chmod g+x lhb.txt
$ ls -l lhb.txt
-rw-r-xr--  1 pratham  staff  0 Mar 10 20:49 lhb.txt
```

When you specify the `a` class, it is almost as if you did not specify any. Let's have a look.

```bash
$ ls -l lhb.txt
-rw-r--r--  1 pratham  staff  0 Mar 10 20:49 lhb.txt

$ chmod +x lhb.txt

$ ls -l lhb.txt
-rwxr-xr-x  1 pratham  staff  0 Mar 10 20:49 lhb.txt

$ chmod 644 lhb.txt #reset permissions

$ chmod a+x lhb.txt

$ ls -l lhb.txt
-rwxr-xr-x  1 pratham  staff  0 Mar 10 20:49 lhb.txt
```

These commands might appear differently, but they have the same outcome.

### Method 3: Use the octal numbers

If you follow the first method, you only enable the executable flag of a file by doing a `+x`, making it such that anyone can execute it.

But, sometimes you might not want everyone to execute a file, maybe it should need some privileges. In that case, you can specify the full set of permissions.

That is usually done by either providing an octal value or a symbolic value to enable file permissions.

This allows you to have a more granular control over how the flags are set. Below is the syntax for using octal values with `chmod` command:

```bash
chmod <octal> <file>
```

If you are not good with numbers, you can use an [online chmod calculator](https://linuxhandbook.com/chmod-calculator/), which helps you generate correct octal values and thus avoid using the wrong value and messing up file permissions.

Say, I want to make the file executable only for the owner and group, I need to know its current permissions first, and add the executable bits to it on top of it using \[chmod-calculator\].

Let's see how to do that.

```bash
$ ls -l lhb.txt
-rw-r--r--  1 pratham  staff  0 Mar 10 20:49 lhb.txt

$ chmod 754 lhb.txt

$ ls -l lhb.txt
-rwxr-xr--  1 pratham  staff  0 Mar 10 20:49 lhb.txt
```

As you can see, only the owner and group can execute the file.

## Conclusion

This article covers making a file executable in a Linux system. It mainly focused on the different ways to use the `chmod` command. If you want to know more about it, we have [a few examples on how to use the chmod command](https://linuxhandbook.com/chmod-command/).