Convert ls -ld to chmod/chown commands

1

0

X home dir permissions: drwxr-xr-x
Y home dir permissions: drwxr-x--x

So my question is, how can i convert drwxr-x--x to a chmod/chown command so I can put the same permissions that Y has on his home dir, on X's home dir?

qwerty1911

Posted 2013-09-11T18:31:28.367

Reputation: 13

Answers

3

You can use chmod's --referenceoption. From man chmod:

   --reference=RFILE
          use RFILE's mode instead of MODE values

So, for example:

$ l -l
total 8.0K
drwx------ 2 terdon terdon 4.0K Sep 11 20:40 bar
drwxr-xr-x 2 terdon terdon 4.0K Sep 11 20:40 foo
$ chmod --reference foo bar
$ ls -l 
total 8.0K
drwxr-xr-x 2 terdon terdon 4.0K Sep 11 20:40 bar
drwxr-xr-x 2 terdon terdon 4.0K Sep 11 20:40 foo

terdon

Posted 2013-09-11T18:31:28.367

Reputation: 45 216

Sorry for late response, but thanks! This was what i was looking for! – qwerty1911 – 2013-10-26T09:54:03.073

1

There is always a way :)

$ ll  | tr 'rwx' 421 | 
       awk '
       {
        split($0,a,""); 
        printf "%d%d%d\n", a[2]+a[3]+a[4], a[5]+a[6]+a[7], a[8]+a[9]+a[10] 
       }' 
020
644
644
755

$ ll
total 2K
-rw-r--r--  1 1K 2013-09-13 03:44 alphabet
-rw-r--r--  1 1K 2013-09-13 03:37 input
drwxr-xr-x+ 1 0K 2013-09-13 04:02 moo

Ярослав Рахматуллин

Posted 2013-09-11T18:31:28.367

Reputation: 9 076