When you are working on the Windows operating system then you may be aware of the “.exe” files which are executable. A series of commands is running behind these “.exe” files to make up an individual program. On the other hand, if you are using the Linux/Ubuntu operating system then there is no division of these files, but you can use either the terminal or GUI to make a file executable. If someone is a new user or unaware of how to make a file executable then this article provides him with a step-by-step explanation.
How to Make Files Executable Using Chmod in Ubuntu 22.04?
Different ways are used in the Linux/Ubuntu terminal to make the file executable. To check the different permissions for a file to be executable, the command to be run in the terminal is given as.
ls -l filename
In the above command
- “ls” lists all the files in the current directory.
- “-l” flag is used with “ls” to show some extra information about the file.
- “filename” is the name of the file for which you want information.
The below figure is the output result for the above command. “-rw-rw-r–” is the information about the file that shows its read-write capability. The owner has both the capability to read and make changes in the file but a group user has the capability to read the file only. The missing “x” from the “-rw-rw-r–” shows that the file is not executable.
To make the file executable there are different ways used in the Linux/Ubuntu operating system such as.
- Make a file executable from the terminal
- Make a file executable by GUI method
Method 1: Make a file executable from the terminal
In the Linux/Ubuntu operating system, most tasks are performed by the terminal. It is a robust tool used by developers to run their programming scripts. But this article gives information on how to make a file executable by using the terminal.
Make a File Executable for Every User
To make a file executable for every user the command to be run in the terminal of the Linux/Ubuntu operating system is given as.
chmod +x filename
In the above command “chmod” is used to make the file executable by adding “x” to its permission. The result of before and after executing the above command is given in the below figure. There is no “x” in the “-rw-rw-r–” that is the information before running the command and “-rwxrwxr-x” includes the “x” is the information after running the above command which shows permission for every user to execute the file.
Make a File Executable for the Specific User
There are different groups available to use with the “chmod” command to make the file executable for the different users.
1: U -Group with “chmod” Command
To make a file executable in such a way that only the user or owner has the permission to execute it then run the below given command in the terminal of Linux/Ubuntu operating system.
chmod u+x filename
In the above command
- “u+x” provides the permission to the user or owner to execute it.
- “filename” is the name of the file which is going to be made executable.
The below figure is the result of the above given command. “-rw-rw-r–” is the information about the file before executing the above command clearly shows that there is no “x” which is the permission to execute the file. “-rwxrw-r–” is the information about the file after executing the above command, “x” is included in this information showing the permission of file to be execute by the owner or user only.
2: G -Group with “chmod” Command
To make a file executable in such a way that every user in the group has the authority to execute it then run the below given command in the terminal of Linux/Ubuntu operating system.
chmod g+x filename
In the above command “g+x” provides the permission to every user in the group to execute the file. The result of before and after executing the above command is given the below figure. There is no “x” in the “-rw-rw-r–” that is information before run the command and “-rw-rwxr–” include the “x” which is the permission for every user in the group to execute the file.
3: O -Group with “chmod” Command
To make a file executable in such a way that all users except the owne and the member of the group has the authority to execute it then run the below given command in the terminal of Linux/Ubuntu operating system.
chmod o+x filename
In the above command “o+x” gives permission to all the users except the owner and the member of a group to execute the file. There is no “x” in the “-rw-rw-r–” that is information before running the command and “-rw-rw-r-x” includes the “x” which is the permission for all the users other than the owner and member of a group to execute the file.
4: A -Group with “chmod” Command
To make a file executable in such a way that each and every user has the authority to execute it then run the below given command in the terminal of Linux/Ubuntu operating system.
chmod a+x filename
In the above command “a+x” gives permission to each and every user to execute the file. The result of before and after executing the above command is given in the below figure. There is no “x” in the “-rw-rw-r–” that is information before run the command and “-rwxrwxr-x” includes the “x” is the information after run the above command which shows permission for every user to execute the file
5: Ug -Group with “chmod” Command
To permit both the owner and every group member to execute the file the command to be run in the Linux/Ubuntu operating system is given as.
chmod ug+x filename
In the above command “ug+x” gives permission to both owner and every member in the group to execute the file. There is no “x” in the “-rw-rw-r–” that is information before running the command and “-rwxrwxr-r–” includes the “x” which is the permission for both owner and every member in the group to execute the file.
Use Sudo with “chmod” Command
To give the permission to execute the file and directories for which currently you do not have the access then use the “sudo” with the “chmod” command. The command to be executed in the terminal is given as.
sudo chmod +x filename
In the above command “sudo” gives privilege to the important files. The result of before and after executing the above command is given in the below figure. There is no “x” in the “-rw-rw-r–” that is information before run the command and “-rwxrwxr-x” includes the “x” is the information after run the above command which shows permission for every user to execute the file.
Make a File Executable Conditionally
To make the file and directories executable conditionally use capital “X” with the “chmod” command. To make a file executable conditionally then execute the below given command.
sudo chmod -R g+x filename
In the above command to make the file executable conditionally use capital “X” with the “chmod” command. The above command is exceptionally applicable for the targeted directories to allow the user to access the directories and subdirectories as compared to the other files. On the other hand if this command is used for the regular files then the file must already have one of permission such as owner, group or all users. The result of the above command is shown in the figure below. Firstly, list the directory which contains the “dir” subdirectory and file “script.sh”. There is no permission to the file but the subdirectory already has the permission. Now we list the subdirectory containing only one file “script1.sh” with no permission to execute. After executing the above command a permission is added to the subdirectory. Therefore it is clear that this gives permissions to the directory only. If we compare the information of subdirectory then “drwxrw-r-x” is the permission information of subdirectory before run the command and “drwxrwxr-x” is the permission information of subdirectory after run the above command.
Reset all the permission
To remove the permission execute the below given command in the terminal.
chmod 644 filename
In the above command “644” is the permission used to move back the file into read write condition by the owner only. The result of before and after execution of this command clearly shows that it returns the file in the read write condition back. “-rw-r–r–” is the first and the final output permission information about the file shown in the below figure.
Make a File Executable by Using the Octal Number
This is another way to make the file executable by using the correct values of the octal number instead of the “+x” flag. The command to use the octal number to make the file executable is given as.
chmod 754 filename
In the above command “754” is the octal number which gives permission to the file to become executable for the user. You can also check the other octal number for different types of permission in the given link. There is no “x” in the “-rw-r–r–” that is information before run the command and “-rwxr-xr–” includes the “x” is the information after run the above command which shows permission for the user to execute the file.
Method 2: Make a File Executable by GUI Method
This is another simple way to make a file executable in the Linux/Ubuntu operating system. The steps to make the file executable by using the GUI method are given below.
Step 1: Navigate the file you want to give permissions. Now right-click on the file for which you want to make an executable then from the dropdown icons click on the properties.
Step 2: The properties window of the file is open now from this click on the “Permissions”. Now from this window find the option “Allow executing file as program” and click to turn on it. In this way, your file achieves the desired executable permissions by the GUI method.
Conclusion
To make a file executable in the Linux/Ubuntu terminal there are different methods availables such as by using the terminal and by using the GUI. There are different ways to use the “chmod” command in the terminal such as “chmod +x filename” is the basic command to give permission to all the users to execute the file. Use the “chmod” command with different groups such as “u, g, o a” you can give different types of permission to make the file executable in the terminal for example, using the “u” group gives only permission to the owner to execute the file.