Last active
September 9, 2017 22:28
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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