How to Make Files Executable Using Chmod in Ubuntu 22.04?


An executable file includes a series of commands that enable an Operating system to run the file directly via a ./ command in the terminal or by double-clicking in GUI (Graphical User Interface). Executable files are essential to run software applications or scripts in the system. In Ubuntu 22.04, any file can be converted to an executable file for a specific user or a group of users via the chmod command.

This article will demonstrate different ways of making a file executable via the chmod command in Ubuntu 22.04 LTS systems. This article is organized as follows:

  • What are File Privileges in Linux/Ubuntu?
  • What is Chmod Command?
  • How to Make a Specific File Executable for Everyone in Linux/Ubuntu?
  • How to Make a Specific File Executable for the Owner/User in Linux/Ubuntu?
  • How to Make a Specific File Executable for a Group of Users in Linux/Ubuntu?
  • How to Make a Specific File Executable for Every Other User in Linux/Ubuntu?
  • How to Make a Specific File Executable via Absolute Mode in Linux/Ubuntu?
  • How to Verify Executable Permissions?
  • Bonus Tip: How to Make a Specific File Executable via GUI?

What are File Privileges in Linux/Ubuntu?

In Ubuntu 22.04, file privileges control the access of a file from different users. For instance, to check the permissions for the “SampleFile.txt”, execute the list command:


From the output, it can be observed that the file privileges of file “SampleFile.txt” is “-rw-rw-r–”. The first set, rw- represents user/owner privileges, the second set, -rw represents a group of users’ privileges, and the third set, r– represents others, i.e., everyone else’s privileges.

In each owner category, there are three permission categories:

  • Read (r): Read privileges enable read privileges.
  • Write (w): Write privileges enable you to write, delete, save, and edit files.
  • Execute (x): Execute privileges enable to run the file.

What is the Chmod Command?

The chmod (Change Mode) command permits the user to modify file permissions. The syntax of chmod command is shown below:

$ chmod <permissions> <filename>

where:

  • Permissions: File privileges for the user group (user/owner, group, others).
  • Filename: Name of the file.

The chmod command can be used to control file permissions and make a file executable for all or specific users and user groups. To demonstrate this, create a bash script, for example, script1.sh. First launch the terminal by pressing a combination of keys [Ctrl + Alt + T]. Next, to create a bash script using the Nano text editor, execute the following command:


This will launch the Nano Text editor, type the below contents of the file:

#!/bin/bash

echo “Hellow World”

echo “This is a Test File”


The above file will display “Hello World” and “This is a Test script”. Save and Close the file by pressing Ctrl+O and Ctrl+X respectively. Next, execute the following command to verify file creation:

The above output indicates that the script script1.sh is successfully created with -rw-rw-r– file permissions, i.e., script1.sh is not executable for any user group. The following sections will demonstrate different ways to make a file executable for different user groups:

How to Make a Specific File Executable for Everyone in Linux/Ubuntu?

To make a file executable for everyone, run the following command:


Or

Where:

  • a: Permissions for all.
  • +x: Adds permission to a file.

The above output indicates that the file permission is changed from -rw-rw-r– to -rwxrwxr-x, i.e., the file execution permission is enabled for everyone.

How to Make a Specific File Executable for the Owner/User in Linux/Ubuntu?

To make a file executable for the owner/user of the file, execute the following command:


Where:

  • u: Permissions for the owner of the file
  • +x: Adds permission to a file.

The above output indicates that the file permission is changed from -rw-rw-r– to -rwxrw-r–, i.e., the execution permission is enabled only for the file owner.

How to Make a Specific File Executable for a Group of Users in Linux/Ubuntu?

To make a file executable for a group of users, run the following command:


Where:

  • g: Permissions for the group.
  • +x: Adds permission to a file.

The above output indicates that the file permission is changed from -rw-rw-r– to -rw-rwxr–, i.e., the execution permission is enabled only for a group of users.

How to Make a Specific File Executable for Every Other User in Linux/Ubuntu?

To make a specific file executable for every other user, i.e., users other than the owner of the file and users added to the groups, execute the following command:


Where:

  • o: Permissions for other users.
  • +x: Adds permission to a file.

The above output indicates that the file permission is changed from -rw-rw-r– to -rw-rw-r-x, i.e., the execution permission is enabled only for every other user.

How to Make a Specific File Executable via Absolute Mode in Linux/Ubuntu?

In the absolute mode, permissions are represented by real numbers by adding 4, 2, and 1 for read, write, and execute respectively for file owners, i.e., the user/owner(u), group(g), and others(o). For example, a file script1.sh has file permissions -rw-rw-r–, i.e., script1.sh is not executable for any file owner. Therefore, in order to make a file script1.sh executable for everyone, i.e., for user/owner, group, and others, run the following command:


Where 775 is computed by:

  • The initial “7” represents the user/owner permissions, which is a sum of 4 (read), 2 (write), and 1 (execute), i.e., the user will have read, write and execute permissions.
  • The second “7” indicates group permissions, where “7” itself is a sum of read (4), write (2), and execute (1).
  • The third “5” indicates others permissions, where “5” is a sum of read(4) and execute (1).

The above output indicates that the file permission is changed from -rw-rw-r– to -rwxrwxr-x, i.e., the file execution permission is enabled for user/owner, group, and others.

Additionally, permissions of 764, 674, and 665 can be used to make a file executable for user/owner, group, and others respectively.

How to Verify Executable Permissions?

To verify executable permissions, run the script.sh file by executing the following command:


Alternatively, run the script.sh file from a different path by specifying the absolute path by executing the following command:
$ /home/linuxuser/Documents/script1.sh

The above output displays the contents of the script1.sh indicating successful execution of the script.

Bonus Tip: How to Make a Specific File Executable via GUI?

The file permissions can also be changed to the executable for all user groups, i.e., user/owner, group, and others via GUI. To make a file executable for everyone via GUI, first, navigate to the file, then right-click on the file and select Properties from the drop-down list:

A “script1.sh Properties” pop-up window will appear. Select the Permissions tab:

Tick the Execute option, i.e., Allow executing files as a program, and close the pop-up window.

This will enable the file to be executable for everyone. Finally, to verify, run the file, script1.sh by double-clicking on it:

Conclusion

Files can conveniently be made executable for the owner, group of users, all other users, and everyone. To make an exe file in Ubuntu 22.04, use the “chmod <type_of_user>+x <filename>” command or the “chmod <permission> <filename>” command. This article demonstrated different ways to make a file executable via the chmod command in Ubuntu 22.04 LTS systems. Once the file is made executable, it can be used to run a script or a software application.

Print Friendly, PDF & Email