Cloning permissions of a folder to another folder
Solution 1
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).
Solution 2
I found a simple solution.
- Create a zero byte
test.txt
file at srcdir, eg/User/test1/srcdir/test.txt
- Make sure dstdir does not exit at target folder, eg
/Users/test2/
- Open Terminal and type following command
sudo ditto /Users/test1/srcdir/test.txt /Users/test2/dstdir/
Note: the last slash at dstdir/
is necessary
ditto will create directory dstdir/
with same permissions as srcdir/
lok
Solution 3
I presume you Googled and found at least:
And this web page also seems to cover some important information (such as fsaclctl
).
indragie
iOS and Mac Developer. I'm working on Flamingo for Mac and previously built Sonora.
Updated on June 11, 2022Comments
-
indragie almost 2 years
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
-
Telemachus over 14 years
fsaclctl
is for turning acls on or off on a filesystem, rather than controlling the acl status of a particular folder. In 10.4, I believe, acl support was available but off by default, so this command came in handy. In 10.5, of course acls are on by default, so it still comes in handy for turning the damn things off. -
indragie over 14 yearsI use chmod all the time, the problem is that I need an automated process to clone the permissions from a source directory to a target directory. Chmod is easy to use manually, but for an automated process it may be a bit hard.
-
Simon Michael over 4 yearsThanks for this, but alas:
chmod: Unknown tag type 'inherited'
. (The ls -e output is0: user:_spotlight inherited allow list,search,readattr,readextattr,readsecurity,file_inherit,directory_inherit
, on macos mojave) -
Anton Korneychuk over 2 years@SimonMichael I faced the same issue and found a workaround. I've added the solution as a separate answer.