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
- Never do this with chmod 777 — it also grants write access to every user on the system. chmod +x is the correct, narrow fix.
- If it still fails with "bad interpreter", the file has Windows line endings: sed -i "s/\r$//" script.sh.
- To make several scripts executable: find . -name "*.sh" -exec chmod +x {} +
- Adding execute to a whole tree? Use chmod -R a+X (capital X) — it only affects directories and files that are already executable, sparing your data files.
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 path resolves fine — the system simply will not let you do that with it.
bad interpreter: No such file or directoryWindows line endings make the shebang point at an interpreter that does not exist.
The commands behind it
Change file permissions with numeric (755, 644) and symbolic (u+x) modes — clearly explained.
lsList the contents of a directory, with options for hidden files, long format, sorting and more.
sedStream-edit text: substitute, delete lines, and edit files in place with -i.
Concepts involved: File permissions · Shebang (#!)
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.