Execute Permissions

One of the most common uses of the binary mask is to set the execute permission. You can create files that contain Linux commands, called shell scripts. To execute the commands in a shell script, you must first indicate that the file is executable—that it contains commands the system can execute. You can do this in several ways, one of which is to set the executable permission on the shell script file. Suppose, for example, that you just completed a shell script file and you need to give it executable permission to run it. You also want to retain read and write permission but deny any access by the group or other users. The octal digit 7 (111) will set all three permissions, including execute (you can also add 4-read, 2-write, and 1-execute to get 7). Using 0 for the group and other users denies them access. This gives you the digits 700, which are equivalent to the binary digits 111 000 000. In this example, the owner permission for the myprog file is set to include execute permission:

$ chmod 700 myprog

If you want others to be able to execute and read the file but not change it, you can set the read and execute permissions and turn off the write permission with the digit 5 (101). In this case, you use the octal digits 755, having the binary equivalent of 111101101:

$ chmod 755 mypro;

Was this article helpful?

0 0

Post a comment