↑↓ move Enter open Esc close

How to Make a File Executable in Linux

Give a script permission to run, and understand why it needs it.

In Linux, "executable" is a permission bit stored with the file, not a .exe extension. A script you just downloaded, copied or created has content but no permission to run, and the system refuses with "Permission denied". One command fixes it.

Step by step

1 Add the execute bit

$ chmod +x script.sh

Grants execute permission to everyone. For a private script, chmod u+x gives it only to you: a better habit on shared machines.

2 Verify

$ ls -l script.sh

You should now see x in the permission string: -rwxr-xr-x. Before the change it read -rw-r--r--.

3 Run it

$ ./script.sh

The ./ tells the shell to look in the current directory, which is deliberately not on PATH: otherwise a malicious file named ls in a shared folder could hijack the real command.

4 Check the shebang

$ head -1 script.sh

The first line must name the interpreter: #!/bin/bash or #!/usr/bin/env python3. Without it, the system does not know what to run the file with.

5 Or skip permissions entirely

$ bash script.sh

Calling the interpreter directly works without the execute bit and without a shebang. Handy for a one-off, but the script stops being independently runnable.

Tips worth knowing

Frequently asked questions

Why do I have to type ./ before the script name?

The current directory is not in PATH, by design. The ./ is an explicit path telling the shell exactly which file to run.

What is the difference between chmod +x and chmod 755?

+x adds the execute bit to whatever permissions exist. 755 sets all nine bits at once to rwxr-xr-x. For a script that already has sensible permissions, +x is the safer, smaller change.

I ran chmod +x and it still says permission denied

Check the directory: you need execute permission on every directory in the path to reach the file. namei -l /full/path shows which one blocks you.

If it goes wrong

The commands behind it

Concepts involved: File permissions · Shebang (#!)

More how-to guides