Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2012 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4274476 to your computer and use it in GitHub Desktop.
Save anonymous/4274476 to your computer and use it in GitHub Desktop.
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