You can set file permissions with the
chmod command. Both the root user and the file's owner can set file permissions. chmod has two modes, symbolic and numeric.The symbolic mode is pretty easy to remember. First, you decide if you set permissions for the user (u), the group (g), others (o), or all of the three (a). Then, you either add a permission (+), remove it (-), or wipe out the previous permissions and add a new one (=). Next, you decide if you set the read permission (r), write permission (w), or execute permission (x). Last, you'll tell
chmod which file's permissions you want to change.Let's have a couple of examples. Suppose we have a regular file called
testfile, and the file has full access permissions for all the groups (long directory listing would show -rwxrwxrwx as the file's permissions).Wipe out all the permissions but add read permission for everybody:
After the command, the file's permissions would be
$ chmod a=r testfileAfter the command, the file's permissions would be
-r--r--r--Add execute permissions for group:
Now, the file's permissions would be
$ chmod g+x testfileNow, the file's permissions would be
-r--r-xr--Add both write and execute permissions for the file's owner. Note how you can set more than one permission at the same time:
After this, the file permissions will be
$ chmod u+wx testfileAfter this, the file permissions will be
-rwxr-xr--Remove the execute permission from both the file's owner and group. Note, again, how you can set them both at once:
Now, the permissions are
$ chmod ug-x testfileNow, the permissions are
-rw-r--r--As a summary, have a look at this quick reference for setting file permissions in symbolic mode:
| Which user? | |
| u | user/owner |
| g | group |
| o | other |
| a | all |
| What to do? | |
| + | add this permission |
| - | remove this permission |
| = | set exactly this permission |
| Which permissions? | |
| r | read |
| w | write |
| x | execute |
No comments:
Post a Comment