TechEarl

How to Make a File Executable on Linux (chmod +x)

Make a script runnable with chmod +x, why the shebang line matters, and how to run it with ./ once the execute bit is set.

Ishan Karunaratne⏱️ 3 min readUpdated
Share thisCopied
Make a Linux script runnable with chmod +x, why the shebang line matters, and how to run it with the ./ prefix.

You wrote a script, ran it, and got Permission denied. The file needs the execute bit:

bash
chmod +x deploy.sh
Terminal showing ls -l of a script at -rw-r--r-- (not executable), then chmod +x, then ls -l showing -rwxr-xr-x with the execute bits set.
Before: rw-r--r-- (no x). After chmod +x: rwxr-xr-x. The script can now be run directly.

Run it with ./

Once executable, run it by path. The ./ is required for a script in the current directory, because . is not on your PATH (for good security reasons):

bash
./deploy.sh

deploy.sh alone gives command not found; ./deploy.sh runs it. To run from anywhere, move it onto your PATH (for example ~/.local/bin or /usr/local/bin).

The shebang decides how it runs

The execute bit only says "this may be run". The first line, the shebang, says with what:

bash
#!/bin/bash
echo "hello from bash"

Common shebangs: #!/bin/bash, #!/usr/bin/env python3, #!/bin/sh. Without a shebang, the file runs under your current shell, which may not be what you wrote it for. #!/usr/bin/env python3 is the portable form because it finds python3 on the PATH rather than assuming a fixed location.

chmod +x adds execute for everyone

Plain chmod +x sets the execute bit for owner, group, and other (it respects your umask, but in practice gives rwxr-xr-x). To make a script executable only by you:

bash
chmod u+x private.sh        # execute for the owner only

That is the tighter choice for anything sensitive; see Linux file permissions explained for the owner/group/other breakdown.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxchmodShell ScriptingPermissionsCLI

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Software Systems Architect · Senior Software Engineer · Engineering Leadership

Software systems architect and senior software engineer with more than two decades designing, building, and running production software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Now a CTO, though what I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts