What does chmod +x filename command do?


You may see a Permission denied error when you try to execute a Python, Shell, or Bash scripts on Linux distributions, Unix, or macOS Terminals.

    Example: zsh shell on macOS

    % ./script.sh
    
    zsh: permission denied: ./script.sh

    Example: Sh Shell

    # ./script.sh
    
    bash: ./script.sh: Permission denied

    Example: Bash Shell

    $ ./script.sh
    
    sh: ./script.sh: Permission denied

Now let's take a look at file permissions using ls command on the script.sh file.

% ls -ls script.sh 

0 -rw-r--r--  1 c2ctechtv  staff  0 Jul 16 02:49 script.sh

Let's try to understand what permissions we have on the file using a table.


    PermissionUserGroupOthers
    Read (r)
    Write (w)
    Execute (x)

As you can see not of the users have the execute permission enabled, hence the erorr.

Let's make use of chmod +x on the file.

% chmod +x script.sh

% ls -l chmod+x script.sh

-rwxr-xr-x  1 c2ctechtv  staff  0 Jul 16 02:49 script.sh
    PermissionUserGroupOthers
    Read (r)
    Write (w)
    Execute (x)

Example of chmod+x command in Terminal

Conclusion: As you can see after executing chmod +x on a file, all the users/groups/others get the rights to execute the file.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap