On Sun, Sep 12, 2021 at 12:43:29PM +1200, Richard Hector wrote: > The context of my question is that I'm creating (or updating) a test copy of > a website. The files are owned by one of two owners, depending on whether > they were written by the server (actually php-fpm). > > To do that, I want all the permissions to remain the same, but the ownership > should be changed according to a provided map. For example, if the old file > was owned by 'mysite', the copy should be owned by 'mysite_test'. If the old > file was owned by 'mysite-run' (the user php runs as), the copy should be > owned by 'mysite_test-run' (if that has to be 'mysite-run_test' to make > things easier, I can live with that).
cd /src mkdir -p /dest rsync -a . /dest/ # The trailing / matters. cd /dest find . -user mysite -exec chown mysite_test {} + find . -user mysite-run -exec chown mysite-run_test {} + This is what I would do. And I would do it *interactively*. If you insist on making a script, then it will be slightly more complicated, because you'll need to add error checking.