Septagram
Septagram

Reputation: 9795

How to set world permissions to be the same as group permissions?

How would you go about changing permissions for a file or in a directory recursively in such a way that group permissions would be copied over to world permissions, with no other changes? For example, to go from this directory listing:

drwxr-x--- 2 septi septi 4096 Jun 29 01:14 example.d
-rw-r----- 1 septi septi    0 Jun 29 01:14 example.r
-rwxr-x--- 1 septi septi    0 Jun 29 01:14 example.x

...to:

drwxr-xr-x 2 septi septi 4096 Jun 29 01:14 example.d
-rw-r--r-- 1 septi septi    0 Jun 29 01:14 example.r
-rwxr-xr-x 1 septi septi    0 Jun 29 01:14 example.x

Upvotes: 2

Views: 141

Answers (1)

Carl Norum
Carl Norum

Reputation: 225112

From the chmod(1) man page (relevant parts extracted):

-R Change the modes of the file hierarchies rooted in the files instead of just the files themselves.

And:

The symbolic mode is described by the following grammar:

who    ::= a | u | g | o
op     ::= + | - | =
perm   ::= r | s | t | w | x | X | u | g | o

The who symbols "u", "g", and "o" specify the user, group, and other parts of the mode bits, respectively. The who symbol a is equivalent to ugo.

The perm symbols represent the portions of the mode bits as follows:

g The group permission bits in the original mode of the file.

So for you:

chmod -R o=g *

Example:

$ ls -l
total 0
drwxr-x---  2 carl  staff  68 Jun 28 10:25 example.d
-rw-r-----  1 carl  staff   0 Jun 28 10:25 example.r
-rwxr-x---  1 carl  staff   0 Jun 28 10:25 example.x
$ chmod -R o=g *
$ ls -l
total 0
drwxr-xr-x  2 carl  staff  68 Jun 28 10:25 example.d
-rw-r--r--  1 carl  staff   0 Jun 28 10:25 example.r
-rwxr-xr-x  1 carl  staff   0 Jun 28 10:25 example.x

Upvotes: 4

Related Questions