Cloning permissions of a folder to another folder
-
19-09-2019 - |
Question
Are there any ways in OS X to clone the permissions of one folder to another. Just to be clear, I don't want to copy the entire folder, just the permissions and then set them on another folder. I think this type of thing could be achieved on Linux/UNIX using the setfacl/getfacl commands, but I'm unsure on how to do this with OS X.
Thanks
Solution
Tested on Mac OS X v10.5.7, in bash:
chown $(stat -f%u:%g "$srcdir") "$dstdir" # Copy owner and group
chmod $(stat -f%Mp%Lp "$srcdir") "$dstdir" # Copy the mode bits
(ls -lde "$srcdir" | tail +2 | sed 's/^ [0-9]*: //'; echo) | chmod -E "$dstdir" # Copy the ACL
Notes: These operations (esp. changing ownership) are likely to require root access; sprinkle with sudo
for best results. Also, that odd echo
command on the last line is there to prevent an error if srcdir doesn't have any ACL entries attached (chmod -E
can cope with blank lines, but not a completely empty input).
OTHER TIPS
What I ended up doing was creating an Objective C method (I was planning on using this in a Cocoa app anyways) that finds out the permissions of a file using a perl script, then uses chmod/chown to apply those permissions.