Linux provides the chmod
command which is used to change file and folder permission. The chmod command is provided by all major Linux distributions like Ubuntu, Debian, CentOS, Mint, Kali, RHEL, SUSE, etc. The chmod command has different options and parameters but the chmod +x is one of the most popular and used options for the chmod. For example, you have created a script file but do not know how to make it executable in order to directly call and execute with the script file name.
Linux is the predecessor of the Unix operating system which is the mother of the operating system families like Linux, BSD, Solaris, etc. So this “chmod +x” command can be easily applied to all Unix and related variant operating systems like BSD, FreeBSD, NetBSD, OpenBSD, MacOSX, Unix without or with little difference.
What is chmod +x?
The +x
parameter is used to add the x
permission which is the symbol for the execute permission. The execution permission will give the execution ability to the owner user or group of the file. The +
will add provided ability and -
minus will remove the provided ability.
List Current User and Group Permission For A File
Before starting to use the “chmod +x” command for the user, group, and others we generally need to use the ls command to list current permission for user, group, and others for the specified file. Just add the -l
option in order list permission, current owner user and group etc.
$ ls -l
We can see that there is a file named backup.sh which is a bash script file. Its privileges are like below where there is no execute privilege for its owner, group or others. As we know the “x” character is used to express execute privilege.
chmod +x Add Execute Privilege For User
The chmod +x can be used to add execution privilege the current owner user of the specified file. In the following example we will add execution privilege for the user ismail to the file named backup.sh
.
$ chmod u+x backup.sh
Also, we can set multiple files executable easily by using glob operation. In the following example, we will make all script files or file with “*.sh” extension executable for their owners or users.
$ chmod u+x *.sh
chmod +x Add Execute Privilege For Group
In Linux files also have an ownership group that is similar to the owner user where the group users have given privileges over the file. The chmod +u can be used to add execution privilege for the current group of the file by using the g before +u.
$ chmod g+x backup.sh
chmod +x Add Execute Privilege For Others
The chmod +x can be also used add execute privileges for others for the specified file. Be warned that this can create security problems becuase all users can execute the specified file without any control.
$ chmod o+x backup.sh
chmod +x Numerical Permission
The +x is used to express execution privilege as a letter. There is also a numerical presentation of the chmod +x where the x is valued as 001 in binary and 1 in decimal. the chmod +x can be expressed as numerical like following commands.
$ chmod 001 backup.sh
Make Executable Via File Manager
Even it is not a command and provided by all file managers you can also use file manager in order to make a script file directly executable by changing the given file properties. Right-click to the bash script file which is “read_line_by_line.sh” in the case. There click on the Properties.
There navigate to the Permissions tab which is similar to the following. There should be a configuration like “Allow executing file as program“. Just enabled it by ticking the checkbox.