I am looking for a way to copy uids and gids for all files of a directory tree from one machine to another. The directory tree is believed to be identical on both machines except that uids and gids got corrupted on the target machine.
The background is that I copied the tree with rsync some months ago, thereby erronously omitting the --numeric-ids option, which caused uids and gids to be wrong in the destination.
Something like
find . -printf "chown %U.%G '%p'\n"
that still works for file names that contain special characters, whitespace, and quotes.
Thanks to Michael Hampton's comment, I tried with rsync in a dry run and grepped the resulting log files to verify that rsync does nothing else but fixing the ids. Since this was the case, a following non-dry run worked fine and fast (after disabeling --checksum) solving my problem.
Maybe still s.o. has a different solution, that avoids grepping the logs or that tolerates changes in the the target directory.
– Helmut Emmelmann Jun 02 '21 at 11:36