The “chmod” command contains various special mode flags to change the access permission of the file. One of them is the “+x” mode which is used to make a file executable in Linux. Making a file executable offers various benefits including security, ease of use, permissions, and automation. This short tutorial is about the quick ways to use the “chmod +x” to make a file executable in Linux.
How to Use Chmod +X to Make a File Executable in Linux
Here, we will describe the various examples that you can try to make any file executable in your Linux system. Additionally, we’ve chosen Ubuntu as the operating system to explain the following examples.
Before moving to the examples of the “chmod” command, let’s open and check the “help” page through the following command:
First, check the permissions of the following “.txt” file:
As you can see in the permissions of the previous file, the owner and group only have read and write permissions, and everyone else only has read permission; no one has the execute permission. The general syntax to make a file executable is as follows:
Example 1: Make a Text File Executable for the Owner
You can give an executable permission for the owner through the “u+x” flag with the “chmod” command as follows:
In the previous command, “x” defines the executable permission and “u” defines the user.
After executing the previous command, it doesn’t give any output. However, you can recheck the permissions using the following “ls” command:
As a result, you can see that the owner has now the executable permission for this “.txt” file.
Example 2: Make a Text File Executable for a Group
You can grant the executable permissions of a file to a group using the “g+x” flag with the “chmod” command as follows;
Here, “g” indicates the group.
Example 3: Make a Text File Executable for Everyone
Instead of the owner or a specific group, there are times when everyone needs to be allowed to execute a file. For this, we need to run the following command:
In the previous command, “a” indicates everyone.
Touch bash.sh
chmod +x bash.sh
Example 4: Make Multiple Files Executable
In the previous three examples, we execute a single file for the owner, group, and everyone. Apart from this, you can also execute multiple files simultaneously with the help of the following command:
To better understand this example, we provide the executable permission to a group for multiple files.
In this way, you can give an executable permission to multiple files simultaneously.
Example 5: Make a Bash File Executable
You can see that in our home directory, there is a Bash file named “linuxhint.sh” and user, group, and no one else has the executable permissions for this file.
Now, using the previous methods, you can also make this file executable for the user, group, and everyone. For your understanding, we make this Bash file executable for the “user”. To do this, we use the following command:
This is how you can also make your Bash file executable in Linux.
Conclusion
In this tutorial, we explored the “chmod +x” command in Linux which is a powerful tool for managing the file permissions to make them executable for users, groups, and everyone on the system. Here, we explained the different examples of making a file executable for users (u+x), groups (g+x), and everyone (a+x). Moreover, it is also described as making multiple files executable simultaneously.