Terminal · foundation
Executable permission
The execute permission bit allows an eligible user to request execution of a regular file and allows traversal or lookup through a directory, subject to other access controls.
Why it matters
A readable script can be passed to an interpreter without being directly executable, while directory execute permission has a different and essential meaning.
Mental model
How to reason about executable permission
Permission checks combine the process's identity with owner, group, or other mode bits; execute is then interpreted according to the object type and requested operation.
Analogy
Read permission lets you inspect a recipe, while execute permission authorizes using it as an instruction entry point; on a directory, execute is the key that permits passing through named doors.
Examples
See the boundary, not just the happy path
Worked example · Make a script directly runnable
chmod u+x deploy.sh && ./deploy.shu+x grants the owner execute permission without changing group or other bits, and ./ names the file directly rather than searching PATH.
Worked example · Run a readable non-executable script
sh checks.shsh is the executable being launched and reads checks.sh as input, so checks.sh itself does not need its execute bit for this invocation.
Useful contrast · Execute on a directory
chmod u+x private-dirFor a directory, execute grants search or traversal through named entries; it does not mean running the directory as a program.
Common mistakes
Misconceptions to remove early
Using chmod 777 as a universal fix
Granting write and execute access to everyone is usually broader than required; determine the needed identity and operation first.
Confusing readable with directly executable
Direct execution checks execute permission, while interpreter file arguments are read as data and therefore follow a different access path.
Quick check
Can you predict the result?
1. Why can sh script.sh work when ./script.sh reports permission denied?
- • sh executes and reads the script as input, while direct execution requires execute permission on the script file.
- • sh automatically changes the file's mode.
- • Direct execution never supports text files.
2. What does execute permission on a directory primarily allow?
Keep building