Skip to content

Latest commit

 

History

History
76 lines (53 loc) · 2.69 KB

chmod_sym_mode.md

File metadata and controls

76 lines (53 loc) · 2.69 KB
layout title tags
manual
chmod [symbolic mode] || Change file modes with symbolic values
chmod

Scenario

When specifying whom (owner, group, others) to have what permission (read, write, execute), we use command chmod.

Abbreviation of chmod

chmod is the combination of two words, change and mode.

Manpage Description

Change file modes or Access Control Lists (ACL).

Modes may be absolute or symbolic.The symbolic mode is described by a simple grammar.

Detail Explain

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.

Version

Mac (BSD) command line utilities

Examples

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 of test_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 of test_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 of test_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