Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple script that can be used to copy the file permissions and ownership for a directory tree to another machine. Run it first on a machine that has the correct permissions, capturing the output to a text file. Transfer that text file to the target machine and run it as a script.
#!/bin/bash
# Create the script that emits values for a single file using stat.
cat >/tmp/fileperms.sh <<FILEPERMS
#!/bin/bash
echo chmod `stat -f '%Lp' \$1` \"\$1\"
echo chown `stat -f '%u' \$1`:`stat -f '%g' \$1` \"\$1\"
FILEPERMS
# Make sure the script is executable
chmod a+x /tmp/fileperms.sh
# Walk the tree, running the script for each file
find . -depth -exec /tmp/fileperms.sh {} \;
# Cleanup
rm /tmp/fileperms.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment