Chmod +X
The Short Answer
On Linux and Unix-like operating systems (MacOS included), the chmod command is used to change the permissions of files and directories. The x option specifically sets the execute permission on a file, allowing it to be run as a program.
For example, to make a script executable by every user on the system, you can use the following command:
$ chmod +x script.shThen run the script directly:
$ ./script.shNote that the + sign here translates to “add permission”.
The Execute Permission For Directories
In the case of directories, the execute permission has a slightly different meaning than for files, as when set, it allows users to list their content using the ls command, or enter them using the cd command.
Setting The Execute Permission For Specific Users
In some cases, you might want to control which user is allowed to execute a file.
To do so, you can use a combination of the letters:
- a for all; which designates all users on the system.
- u for user; which is the user account that created the file or has been assigned ownership of the file
- g for group; which is a collection of user accounts, such as members of the same team, that have been granted certain permissions on the file.
- o for others; which are all other users who are not the owner or members of the group associated with the file.
Use u+x to give execute permission to the owner of the file only

Use ug+x to give execute permission to the owner of the file and the group

Use a+x to give execute permission to everyone

Note that in this last case, executing chmod a+x has the same effect as chmod +x.
Setting The Execute Permission Conditionally
The X (uppercase x) option allows to conditionally set the execute permission of files and directories.
When used:
- If the target is a directory, then it sets the execute permission for the owner, the group, and the others, allowing them to list and enter the directory.
- If the target is a regular file, then it doesn’t set the execute permission, unless it is already enabled on at least one of the owner, the group, or the others.
This option is particularly useful when you want to recursively change the permission of a directory and its subdirectories, without affecting the regular files themselves.
For example, let’s consider the following tmp directory:

Running the chmod -R g+X command on this directory will set the execute permission for the group on:
- The tmp directory.
- The dir\_1 subdirectory.
- The script\_1.sh file.
But will leave the permissions of the script.sh file unchanged.

Note that running chmod +X will have the same effect as running chmod a+X.
Using the chmod command with sudo
The sudo command is used to execute a command as the superuser (or root).
Executing the chmod command with sudo allows you to modify the permissions of files or directories that you do not have access to as the current user.
For example, you can use the sudo chmod +x command on a system file to give permission to all users to execute it.
$ sudo chmod +x /sbin/rebootIt is important to note that giving the execute permission to all users to a file or directory belonging to the system may lead to security vulnerabilities and have unintended consequences.
Related articles
Bash Comments
Comments will help make your scripts more readable
Reading User Input
Via command line arguments and prompting users for input
Curl Post Request
Use cURL to send data to a server
Upload Files With curl
Learn how to upload a file to FTP, SFTP servers, Artifactory, and AWS S3 using the curl command.
How To Copy A Directory In Linux
Learn how to copy directories and their content in Linux using the cp command with options like -r for recursive copying, -i for interactive mode, and -a for preserving attributes.
Create Groups In Linux
Learn how to manually and automatically create and list groups in Linux.
How to Check the Size of Folders in Linux
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Count Files in Linux
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
List Open Ports in Linux
Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.
Format Command Output In Linux
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Create Directories Recursively With mkdir
Learn how to recursively create nested directories using the mkdir command, Bash scripts, and Python scripts.
Remover Users in Linux
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.