Skip to content

Instantly share code, notes, and snippets.

@wwalker
Last active September 9, 2017 22:28
Show Gist options
  • Save wwalker/5768581 to your computer and use it in GitHub Desktop.
Save wwalker/5768581 to your computer and use it in GitHub Desktop.
copy the permissions from one tree to another that have identical directory/file structure
find . -print0 | grep -Z -z -v '^\.$' | xargs -0 stat -c '%a:%U:%G:%n' | perl -n -e '($p, $u, $g, $f) = (/(.*?):(.*?):(.*?):(.*)/); print "chown $u:$g \"$f\"\n"; print "chmod $p \"$f\"\n";' > /tmp/doit.sh
cd /path/to/source; find . -print0 | grep -Z -z -v '^\.$' | xargs -0 stat -c '%a:%U:%G:%n' | perl -n -e '($p, $u, $g, $f) = (/(.*?):(.*?):(.*?):(.*)/); `chown $u:$g "$f"`; `chmod $p "$f"`;' | ssh target_host 'cat > /tmp/doit.sh; cd /path/to/target; . /tmp/doit.sh; rm /tmp/doit.sh'
On the target:
cd /path/to/targetdir; find . -print0 | grep -Z -z -v '^\.$' | ssh source 'cd /path/to/sourcedir; xargs -0 stat -c "%a:%U:%G:%n"' | perl -n -e '($p, $u, $g, $f) = (/(.*?):(.*?):(.*?):(.*)/); `chown $u:$g "$f"`; `chmod $p "$f"`;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment