1

How do I copy all the folder, subfolders and files permissions (recursively) from /www_03062018 to my new /www ?

I came across this question on Super User.

chmod --reference=RFile file

Which didn't help much, it did apply a change for the main folder /www but didn't apply on its subfolders and files.

I have tried:

chmod -R --reference=/www_03062018 /www

and it didn't work.

My situation:

I have 2 folders on my Ubuntu machine: /www and /www_03062018.

/www is a "git clone" from the production machine.

/www_03062018 is my old directory that i used to work on and upload files via FTP.

I started to use GIT and when I clone a directory its folder ownerships and file accesses settings don't get cloned along with it.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Kar19
  • 450
  • 1
  • 6
  • 25
  • Git does neither record permissions nor ownership except for the `x` bit. You need some other means to maintain those file attributes. – PerlDuck Jun 03 '18 at 11:57
  • Yes i figured this out, i still have my backed up folder i used to work on, so i can copy its permissions tree maybe. if i can apply this to one folder, im sure there is a command that does that recursively @PerlDuck – Kar19 Jun 03 '18 at 11:58
  • 1
    And what is wrong with doing `cp -R --preserve /www /www_03062018`? – George Udosen Jun 03 '18 at 11:59
  • @GeorgeUdosen because of the last part of my post. i explained why. – Kar19 Jun 03 '18 at 12:02
  • `-p` is not a valid command `chmod: invalid option -- 'p' Try chmod --help for more information.` @PerlDuck – Kar19 Jun 03 '18 at 12:02
  • 1
    then there is `cp -R --attributes-only /www_03062018 /www` – George Udosen Jun 03 '18 at 12:12
  • @GeorgeUdosen it just copied `/www_03062018` into `/www` as a new folder – Kar19 Jun 03 '18 at 12:25
  • 1
    Yes that was what i thought you were about so I posted a second command using `cp` that only copies the attributes over! – George Udosen Jun 03 '18 at 12:33
  • For CHMOD this worked: `find . -path ./.git -prune -or -exec chmod --reference '/www_03062018/{}' '{}' ';'` And for CHOWN this worked: `find . -path ./.git -prune -or -exec chown --reference '/www_03062018/{}' '{}' ';'` – Kar19 Jun 03 '18 at 13:10

1 Answers1

2

cd to the new directory which you want to give new permissions - in my case:

cd /www

For CHMOD this worked:

find . -path ./.git -prune -or -exec chmod --reference '/www_03062018/{}' '{}' ';' 

And for CHOWN this worked:

find . -path ./.git -prune -or -exec chown --reference '/www_03062018/{}' '{}' ';'

Hope this helps others :) !

Kar19
  • 450
  • 1
  • 6
  • 25