Every file or directory in Linux has “read”, “write”, and “execute” permissions. These permissions are assigned by default when the directory or file is created. But {:gap {:kind :userinput}} can easily change it via the CLI and GUI. In CLI, it can be modified using the “chmod” command. While in GUI, the file “properties” window helps the user to perform this task.
This guide provides the possible effects to make the files executable in Linux through CLI and GUI. The outline of this article is as follows:
Let’s start with the first method.
Method 1: Make File Executable in Linux via CLI
Linux OS offers the productive commands to access and manage the system completely. This method comprises step-by-step instructions to make a file executable in Linux using the command line interface for the owner, group, others, and all.
Before moving on to the practical implementation, let’s look into the specific “NewFile” file permissions:
$ ls -l
The highlighted part in the output displays that the “NewFile” does not have execution rights for any user. Now, let’s make it executable using the steps.
Step 1: Change the File Permissions
First, change the permissions of the specific file with the help of the “chmod” command. As an example. A file is created in the “nano” text editor having the name “NewFile” and the following content:
$ nano NewFile
Now, the execution privileges can be granted to a specific user, following their key names, which are demonstrated below.
- u: Denotes permissions for the owner of the file.
- g: Represents permissions for the group of a file.
- o: Allows permissions for other users.
- a: Accesses permissions for all.
Make File Executable for Owner
$ chmod u+x NewFile
Make File Executable for Group
$ chmod g+x NewFile
Make File Executable for Others
$ chmod o+x NewFile
Make File Executable for All
$ chmod a+x NewFile
OR
$ chmod +x NewFile
In this scenario the permissions are allowed to all users of current OS by utilizing the below-mentioned command:
$ chmod +x NewFile
Now, every user of the current OS can execute the “NewFile” file
Step 2: Execute the File
Once the execute permission is assigned to “NewFile”, run it in this way for the verification:
$ ./NewFile
Hence, the “NewFile” is executed successfully and show the output of the “ls -l” command that is described in it.
Note: If the file has the “.bin” or “.run” extension, then use this file extension with its name. The generalized syntax for making these files executable is written below:
$ chmod u+x [file-name] [file-extension]
Make File Executable Using Octal Numbers
Apart from the above classes, the user can also change the file permissions using the “octal” numbers. While each octal value represents either “read”, “write”, or “execute” permission. Look at the table to understand what octal values are in the permissions scenario.
Octal-Value | Permissions Representation | Permissions Description |
0 | — | Represents no permission |
1 | –x | Allow only the execute permission. |
2 | -w- | Shows the write permissions only. |
3 | -wx | Write and execute permissions, i.e. (1. execute) and (2. write)=3 |
4 | r– | Read permissions only. |
5 | r-x | Read and execute permission as (1. execute) and (4. read)=5 |
6 | rw- | Read and write permissions as (4. read) and (2. write)=6 |
7 | rwx | All permissions such as (1. execute), (2. write) and (4. read)=7 |
Example
Use the above octal values to make the “File1” file executable for its owner, group, and others. Its permissions are shown below:
$ ls -l File1
Type the octal value in the set as “6(4 read)(2 write)” for the owner, “7 (4 read)(2 write)(1 execute)” for the group, “4(4 read)” for others with the chmod command. This octal value will make the file executable only for its group:
$ chmod 674 File1
The output verifies that only the “itslinuxfoss” group is allowed to execute the “File1”.
Method 2: How to Make File Executable in Linux via GUI?
The user can also execute the file with the help of the graphical user interface. Follow the steps below to run the .bin file visa GUI
Step 1: Open the file Properties
Open the directory where the desired file is saved or downloaded. In this case, the file named “Extra.bin” is located in the “Documents” directory:
Right-click on the file and choose the “Properties” option from the dropdown list:
The “Extra.bin Properties” window will be opened:
Step 2: Change the File Permissions
Hit the “Permission” icon in the menu bar of the “properties” window. Tick the highlighted checkbox “Allow executing file as a program”:
Step 3: Execute the file
Now, double-click on the “Extra.bin” file to run it:
That’s how to make files executable in Linux using CLI and GUI.
Conclusion
All the commonly used Linux distributions provide the “chmod” command to make the file executable. The “chmod” command assigns the execute permissions in two ways that are using the “permission levels” or the “octal values”. Furthermore, {:gap {:kind :userinput}} can also perform this task efficiently through the Graphical User Interface. This guide has provided CLI and GUI methods to make file executable in Linux.