chmod +x
A new script file is like a locked toy box, so the computer will not play with it until you give it permission. chmod +x is the key that says 'yes, this file is allowed to run'.
In this page:
Syntax
chmod +x file_name
./file_name
chmod +x
chmod +x file adds execute permission to a file, which is required before you can run a script with ./script.sh. Without it, the shell refuses with a "permission denied" error. This is a one-time step needed after creating a new script file.
Warning:
Forgetting
chmod +x is the most common reason a new script fails to run directly.Example: chmod +x
# Check current permissions
ls -l script.sh
# Add execute permission for the owner
chmod +x script.sh
# Now it can be run directly
./script.sh
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Running
chmod +xon the wrong path, so the script still givesPermission denied. - Using
chmod 777whenchmod +x(orchmod 755) is enough, which makes the file writable by everyone. - Forgetting that files copied from some file systems lose the execute bit, so it must be set again.
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: