Do you want to know what does "
chmod +x" means in Linux?
chmod is a very useful command, made to manage file modes in Linux.
Each file and directory in Linux can hold three types of permissions: read (
r), write (
w), and execute (
x). Each permission may be
off for each of three categories of users: the file or directory owner; other people in the same group as the owner; and all others.
One of the most used
chmod command is
chmod +x which uses
+x switch to modify the execution permission. In this article we are going to show you different use cases for user or owner, group and others roles.
What does chmod +x do?
chmod +x following by a filename, usually a script, means that you make it executable.
In Ubuntu or other distro that uses GNOME, you can achieve the same result by right click on your file/script and choose Properties, then switch to Permissions tab, tick the Allow executing file as program checkbox.
Operation not permitted error with chmod?
chmod command, include
chmod +x usually produces no response. But in some cases, you will encounter this error :
chmod: changing permissions of '/usr/share/test/path': Operation not permitted.
The error means you do not have the rights to change permission on
/usr/share/test/path, which is a system directory. In this case, you must use your
root privileges through
sudo command (but be careful as
sudo has the ability to break your system).
sudo chmod +x /usr/share/test/path
If you see no response, the command ran successfully and the permissions have been changed.
chmod u+x versus chmod +x comparison
A huge number of tutorials on the internet use
chmod u+x in their tutorials for demonstration purpose. If you actually run
chmod u+x and compare with
chmod +x, you should see no difference in most cases.
- u stands for user.
- g stands for group.
- o stands for others.
- a stands for all.
That means that
chmod u+x filename will grant the execution permission to the owner of the file and no one else, whereas
chmod +x filename is the same as
chmod a+x filename (which means give everyone the rights to run the file).
chmod +x vs chmod 777 comparison
Instead of using
ugoa shorthand for permissions,
chmod allows you to use numbers, which is called
octal mode number notation.
File permissions in Linux are stored in
file mode bits, and those bits varies between user groups.
- r (read) = 4
- w (write) = 2
- x (execute) = 1
To set permission to a group using numbers, you need to add the digits according to what was mentioned above. For example:
- To represent rwx triplet use 4+2+1=7
- To represent rw- triplet use 4+2+0=6
- To represent r– triplet use 4+0+0=4
- To represent r-x triplet use 4+0+1=5
To be able to compare
chmod +x with
chmod 777, we should look at them from the same perspective:
chmod +xis equal to
chmod a+x, which means "add executable permission to
somefilefor all user groups"
chmod 777is equal to
chmod a=rwx, which means "set read, write, executable permission to
somefilefor all user groups"
These commands usually produce the same results, but in reality they are fundamentally different.
chmod +x FAQ
We’ve collected a bunch of frequently asked questions. Please review them carefully before you ask any other.
- How to set executable permission to a file for user?
We can use +u in order to enable user execution right of a file. For example: enable user execution of script.sh like this : chmod u+x script.sh
- How to set executable permission to a file for group?
We can use +g in order to enable group execution right of a file. For example: enable group execution permission of script.sh like this : chmod g+x script.sh
- How to set executable permission to a file for all users and groups?
We can use +a in order to give all users regardless of their groups the execution right to a file. For example: enable execution permission of script.sh for all users : chmod a+x script.sh