You can set the execute permission on a file in a Unix-like operating system, such as Linux or macOS, using the
chmod command. Here’s how you can do it:
- Open your terminal.
- Use the
chmodcommand to set the execute permission. The basic syntax is as follows:
chmod +x filename
filename with the name of the file for which you want to set the execute permission.
For example, if you have a file named “my_script.sh” and you want to make it executable, you would run:
chmod +x my_script.sh
- Verify that the execute permission has been set by using the
lscommand with the
-loption to list the file’s permissions. You should see an “x” in the permissions field for the owner of the file.
ls -l filename
ls -l my_script.sh
The output should show something like:
-rwxr-xr-x 1 user user 12345 Sep 4 10:00 my_script.sh
In this example, the “x” in the permission field indicates that the file is now executable.
That’s it! You have set the execute permission on the file, and you can now run it as a script or program.