← Back to Bash Course | Chapter 1: Setup & Basics | Lesson 3 of 12

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:

  1. chmod +x
Syntax
bash
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

bash
# 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
  1. Running chmod +x on the wrong path, so the script still gives Permission denied.
  2. Using chmod 777 when chmod +x (or chmod 755) is enough, which makes the file writable by everyone.
  3. Forgetting that files copied from some file systems lose the execute bit, so it must be set again.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.