layout | title | tags |
---|---|---|
manual |
chmod [symbolic mode] || Change file modes with symbolic values |
chmod |
When specifying whom
(owner, group, others
) to have what permission
(read, write, execute
), we use command chmod
.
chmod
is the combination of two words, change
and mode
.
Change file modes
or Access Control Lists (ACL)
.
Modes may be absolute
or symbolic
.The symbolic mode is described by a simple grammar.
The grammar is simple.
Who
(who) op
(has/doesn't has) perm
(permission).
The who
symbols are u
(user), g
(group), o
(others) and a
(all, equivalent to ugo).
The op
symbos are +
, -
and =
.
+
: Set or change permission if specified.
-
: Clear the specified permission.
=
: Reset permission with specified values. This op clears all permissions before setting the new ones.
The perm
(permission) symbols are r
(read), s
(set uid or gid), t
(sticky), w
(write), x
(execute), X
(execute, if the entry is a directory), u
(the user permission), g
(the group permission) and o
(the other permission).
Now let's look at some examples.
Let's say if a file has a 755 permission. And we'd like the group users to gain the write permission. We can use chmod g+w file
to grant the write permission. Now we'll have a 775 permission to this file.
And if we'd like to remove the execute permission from the others
. We can use chmod o-x file
to remove the execute permission. Now we'll have a 754 permission to this file.
And if we'd like to reset permission for the group users. We can use chmod g=w file
. Now we'll have a 725 permission to this file.
Mac (BSD) command line utilities
Here are three examples chmod g+w
, chmod o-x
and chmod g=w
to a 755
permission file.
chmod g+w
Add write permission oftest_chmod
to the group users.
$ls -l
drwxr-xr-x 2 user staff 64 May 29 15:20 test_chmod
$chmod g+w test_chmod
$ls -l
drwxrwxr-x 2 user staff 64 May 29 15:20 test_chmod
chmod o-x
Clear execute permission oftest_chmod
to the other users.
$ls -l
drwxr-xr-x 2 user staff 64 May 29 15:20 test_chmod
$chmod o-x test_chmod
$ls -l
drwxr-xr-- 2 user staff 64 May 29 15:20 test_chmod
chmod g=w
Reset permission oftest_chmod
to the group users.
$ls -l
drwxr-xr-x 2 user staff 64 May 29 15:20 test_chmod
$chmod g=w test_chmod
$ls -l
drwx-w-r-x 2 user staff 64 May 29 15:20 test_chmod