Skip to content

Instantly share code, notes, and snippets.

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.
# Create the script that emits values for a single file using stat.
cat >/tmp/ <<FILEPERMS
echo chmod `stat -f '%Lp' \$1` \"\$1\"
echo chown `stat -f '%u' \$1`:`stat -f '%g' \$1` \"\$1\"
# Make sure the script is executable
chmod a+x /tmp/
# Walk the tree, running the script for each file
find . -depth -exec /tmp/ {} \;
# Cleanup
rm /tmp/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment