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
chmod
command to set the execute permission. The basic syntax is as follows:
chmod +x filename
Replace 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
ls
command with the-l
option to list the file’s permissions. You should see an “x” in the permissions field for the owner of the file.
ls -l filename
For example:
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.