The mtree utility compares the file hierarchy rooted in the current directory against a specification read from the standard input. Messages are written to the standard output for any files whose characteristics do not match the specifications, or which are missing from either the file hierarchy or the specification.
There are many uses for mtree, as I'm discovering. Today, I used mtree to quickly repair permissions on a large file structure which I had to restore from backups. Our backup system is a disk-based server utilizing rsync to transfer the files. Restoring about 300GB of data yesterday, I erroneously used rsync -rv directory host:/directory instead of rsync -av directory host:/directory. This meant that ALL files were owned by the user which restored the files, root.
I thought it would be a simple matter of running rsync again, but rsync appeared to want to transfer all the files again, which I didn't have the patience for. Along came mtree to the rescue.
Using mtree, I created a specification file from the backup copy (with the correct permissions) with the following command:
cd /path/to/directory mtree -c > spec.txt
This done, I copied the file to the system which had the restore operation, and ran the following command to fix all the file meta data:
cd /path/to/directory mtree -f spec.txt -U
All was well with the world.