Linux: Copying file/directory permissions
📄 Wiki page | 🕑 Last updated: Feb 15, 2024You can use this command to copy the full permissions (both standard Linux permissions and ACLs) from path1 to path2:
getfacl path1 | setfacl --set-file=- path2
The output from getfacl command should look something like this:
# file: path1
# owner: n
# group: n
user::rw-
group::r--
other::r--
By providing the --set-file=- option, we can use this exact output as an input to the setfacl command.
Alternatives
If you need to just copy the mode bits, you can use the chmod command:
chmod --reference path1 path2
The same syntax also works for chown and chgrp commands:
chown --reference path1 path2
chgrp --reference path1 path2