TL;DR
To make a file executable in Linux, follow these steps
- Open Terminal.
- Run ls -l to check current permissions.
- Run chmod u+x [filename] to set execute permission for the owner.
- For group or others, use chmod g+x [filename] or chmod o+x [filename].
To find out more about how to make a file executable in Linux and resolve its common issues, read the step-by-step guide below.
Are you struggling to run your scripts or programs in Linux because they aren’t executable? This post will show you how to make any file executable in Linux. You’ll learn different methods and practical steps, and I’ll cover common errors you might face. You can expect to find detailed explanations on using the chmod
command, adding a shebang line, and even using the GUI. Plus, you’ll learn how to set executable permissions for the owner, a group, and all users.
What It Means to Make a File Executable?
Making a file executable means giving the file permission to be run as a program. In Linux, files typically have different types of permissions, like read, write, and execute. When a file is executable, you can run it directly from the command line or by double-clicking it in a file manager.
For example:
If you have a script that you wrote in a text editor, it won’t do anything if you try to run it unless you make it executable first. By changing the file’s permissions to include execute permissions, you tell the system that this file is meant to be run as a program.
How to Make a File Executable in Linux
To make a file executable in Linux, you have several options. Use the chmod
command by navigating to your file in Terminal and running chmod +x [filename]
. You can also add a shebang (#!
) line at the top of your script, like #!/bin/bash
, save it, then run chmod +x [filename]
. Another method is to use the GUI: right-click the file, select Properties, and check the Execute box under Permissions. Now, your file is executable.
Here’s a breakdown of each of these methods:
1. Use chmod Command
Before learning to make a file executable in Linux, you should know the basics of file permissions. This includes read (r), write (w), and execute (x), which can be assigned to the owner, group, and others. The ls
and -l
command displays permissions, and the chmod
command is used to modify them. Once you know about the file permissions for a certain file, use chmod
to modify its access permissions. Here’s how to do it:
- Run the
ll
command to view the permission of the file before making it executable.

- To make a file executable in Linux Terminal, you need to set the execute permission for the user group to which the file belongs. Here is the command to do that:
chmod u+x [filename]
- This command sets the execute permission (x) for the user (u) file group. You can also set the execute permission for the group (g) or others (o) by replacing u with g or o, respectively.

2. Use Shebang Notation
Another way to make a file executable in Linux is by using the shebang (#!) notation. It’s a special sequence of characters that tells the shell what interpreter to use to run the script. Here’s how to add a shebang to make a file executable in Linux:
- Right-click the script file, then open it using the text editor app.

- Add the shebang line (
#!
) at the top of the file, specifying the path to the interpreter. For example, if you want to use the Bash interpreter, the shebang line should be!/bin/bash

- Save the file with a meaningful name and the
.sh
extension.

- Once you’ve added the shebang to the file, head to the Terminal and navigate to the directory where the script file is located.
cd ~/directory-name
- Next, run the
ls
command to confirm whether the script file exists in that directory.

- Run the following command to make the script file executable while replacing “script.sh” with the actual name of your script file:
chmod +x script.sh
- Again, run the
ls
command to see if the file has become executable. If it is, it’ll show in a different color.

- You can now execute the script by running
./script.sh
in the Terminal. Theshebang
line ensures that the correct interpreter is used to execute the script. Here is the output:

3. Use Linux GUI
You can also make a file executable in Linux using the graphical user interface (GUI). This method is very simple and easy for people who prefer to use the graphical representation of the Linux distros. Here are the steps to follow:
- Right-click on the file you want to make executable and select Properties.

- Then navigate to the Permissions tab.

- From there, you can check the Execute box to make the file executable.

- Once done, head to the Terminal window and run the script with the following command:
./filename
- Now, you should see the following output:

Setting Executable Permissions for Different Users
1. Make the File Executable for the Owner
In Linux, making a file executable for the owner allows the file’s creator to execute it while restricting access to others. This is useful for personal scripts or applications that only the owner should run. The chmod command is used to change file permissions.
- Open the Terminal.
- Use the cd command to change to the directory where your file is located.
cd /path/to/your/file
Replace the /path/to/your/file with the directory name you want to move.

- Use the chmod command with the u+x option to add execute permissions for the owner.
chmod u+x filename
This command modifies the file’s permissions so that the owner can execute it.

- Check the file permissions by running the command:
ls -l filename
The output should show an x in the owner’s permission set, indicating that the file is executable by the owner (e.g., -rwx——).

2. Make the File Executable for a Group of Users
Making a file executable for a group of users allows members of a specific group to execute the file. This is useful in collaborative environments where multiple users need access to the same executable file. Linux uses group-based permissions to manage this.
- Access the terminal on your Linux system. Navigate to the directory containing the file:
cd /path/to/your/file
- Use the ls -l command to see the current group owner of the file.
ls -l filename
The group owner is listed in the output (e.g., -rw-r—– 1 owner group filename).

- Use the chown command to change the group owner if needed.
sudo chown :groupname filename

- Use the chmod command with the g+x option to add execute permissions for the group.
chmod g+x filename
This command modifies the file’s permissions so that the group can execute it.

- Check the file permissions using the command:
ls -l filename
The output should show an x in the group’s permission set, indicating that the file is executable by the group (e.g., -rwxr-x—).

3. Make the File Executable for Every Other User
Making a file executable for every other user allows all users on the system to execute the file. This is useful for publicly accessible scripts or applications that need to be run by anyone. However, it comes with security implications that need to be carefully considered.
- Launch your Terminal window and access the directory containing the file:
cd /path/to/your/file
- Run the following command to add execute permissions for others.
chmod o+x filename
This command modifies the file’s permissions so that all users can execute it.

- Check the file permissions using ls -l.
ls -l filename
The output should show an x in the others’ permission set, indicating that the file is executable by others (e.g., -rwxr-xr-x).

5 Common Issues When Making a File Executable
When making a file executable in Linux, you may encounter a few common issues or errors. Here are five of them, along with their easy solutions to help you troubleshoot:
- 🛡️ Executing Commands with Superuser Privileges: If you encounter a “Permission denied” error, it’s often because the command requires elevated permissions. In such a case, use the sudo command to execute the file as a superuser. Here’s an example of how you do it:
sudo ./file_name
. - 📂 Handling Read-Only File Systems: If you experience a “File is in a read-only file system” error, it means you’re trying to modify a file in a read-only location. You can either move the file to a different directory or remount the file system as read-write. Here’s how you remount the file system:
sudo mount -o remount,rw /
. - 🚨 Reacquiring Corrupted Files: If you encounter a “File is corrupted” error, the file you’re trying to use might have been damaged or improperly downloaded. Consider redownloading the file or acquiring a different copy to resolve this issue.
- 🔍 Installing Missing Commands: A “Command not found” error typically suggests that the command you’re trying to use is not installed on your system or not available in your current
PATH
. To fix this, install the necessary command or add the directory containing the command to yourPATH
variable. Here’s an example of installing a command:sudo apt-get install command_name
. - 📝 Renaming Files with Correct Extensions: If you’re experiencing a “File has no extension” issue, it’s likely because the file you’re trying to use lacks a proper extension. To resolve this, rename the file and add an appropriate extension. For instance, if it’s a shell script, you should rename it with a “.sh” extension. You can do this with the following command:
mv file_name file_name.sh
.
Key Takeaways
In this article, I’ve covered how to make a file executable in Linux using the chmod
command, adding a shebang line, and using the GUI. I also showed you how to set executable permissions for the owner, a group, and all users.
If you found this guide helpful, you might want to explore about managing files in Linux. For additional skills:
- Learn how to display hidden files in Linux, which will help you manage all files, even those not immediately visible.
- Explore different methods to view Linux file content, enhancing your ability to inspect and manipulate files efficiently.
- Understand ways to concatenate files in Linux to streamline your workflow by combining multiple files into one, making data management easier and more effective.
Frequently Asked Questions
How to change file ownership in Linux?
chown
command. Here’s the syntax for using this command chown [new_owner]:[new_group] [filename]
. The [new_owner]
argument is the new owner of the file, and the [new_group]
argument is the new group to which the file will belong. If you want to keep the same group, you can omit the :[new_group]
part of the command.How do I check if a file is executable in Linux?
ls
command with the -l
option. This will show you the file permissions for the file. Here’s an example, ls -l [filename]
. You will see an x
in the file permissions if the file is executable. For example, if the file is named “myscript.sh”, and it’s executable, you will see something like this -rwxr-xr-x 1 user user 1234 Apr 28 10:00 myscript.sh
. The first character (-
) indicates that it’s a regular file. The next three characters (rwx
) indicate the permissions for the owner of the file. The next three characters (r-x
) indicate the permissions for the group, and the last three characters (r-x
) indicate the permissions for everyone else. The x
in the second set of permissions (rwx
) indicates that the file is executable.What to do if the executable file does not have an extension?
file
command, which can provide information on the file type, its encoding, and other details. Once the file type is identified, the appropriate extension can be added using the mv
command.How do I make a file executable in Linux by default?
umask
) to 022
. This will ensure that any new files you create have the executable bit set by default. To set the default umask
, you can add the following line to your .bashrc
or .bash_profile
file umask 022
. This will set the default file creation mask to 022
, which means that new files will have permissions of 644
(readable and writable by the owner, readable by everyone else). If you want new files to be executable by default, you can set the umask
to 002
, which will give new files permissions of 755
(readable, writable, and executable by the owner, readable and executable by everyone else).