Make a file executable

Low risk
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Adds execute permission to a script or binary so it can be run directly, the usual fix for "permission denied" on a freshly written script.

filespermissionschmodexecutable

Parameters

File to make executable.

Commands

Check the file's current permissions

ls -l "<file>"

Add execute permission for user, group, and others

chmod +x "<file>"

Verification

ls -l "<file>"

The permission string now contains x, e.g. -rwxr-xr-x.

Undo

Remove the execute permission again

chmod -x "<file>"

Pitfalls

  • The script also needs a correct shebang line (e.g. "#!/usr/bin/env bash") to run directly.
  • On Windows, execution policy (Get-ExecutionPolicy) governs whether .ps1 scripts run, not a file permission.
  • Files on some mounted volumes (e.g. exFAT) ignore permission bits entirely.

Related