I use rsync for copying certain files to a folder (the directories are intentionally left out) which is synced to other devices with Syncthing:

find /mnt/media/ -name "*.epub" > /home/user/.logs/rsync/epub-paths.txt && \
rsync --archive --files-from=/home/user/.logs/rsync/epub-paths.txt  \
--no-relative / /home/user/Documents/ebooks/

None of the files are created by me, the filenames often contain spaces and characters which are problematic in the shell. Sadly I can't easily rename everything on the mounted source drive.

I planned using detox to recursively process the destination ebook directory, but the program doesn't replace existing files — which in this case are all identical. Unfortunately, even if I all duplicates are removed, rsync still transfers gigabytes of data in vain each time the script is run (currently daily). Using jdupes or similar to remove the duplicate files afterwards isn't an actual solution.

In short: don't modify any local data, rewrite the filenames (and folders, if I had any) in the rsync transfer before being written on the destination.

1 Answer 1


You may be able to use NULL-terminated arguments:

find /mnt/media/ -name '*.epub' -print0 |
    rsync -as --files-from=- --from0 --no-relative / /home/user/Documents/ebooks

Or if your find is POSIX and doesn't have the -print0 option, try this slightly less comprehensive solution:

find /mnt/media/ -name '*.epub' |
    rsync -as --files-from=- --no-relative / /home/user/Documents/ebooks
  • Both solutions appear to copy filenames with spaces, I tested by creating a file with $ touch /tmp/'book title .epub' — rsync version 3.2.7 protocol version 31
    – user598527
    Jul 24, 2023 at 13:41
  • Are the newlines and four spaces preceding rsync in the answer intentional?
    – user598527
    Jul 24, 2023 at 13:43
  • They are intentional but not necessary, @user598527. I use this as a visual indicator that it's a continuation line (and you can enter either pair of lines directly "as is" in any sh-style shell). Since you can use the first suggestion, take it in preference to the second; it will work will all possible filenames whereas the second can only work with a (large) subset of them Jul 24, 2023 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .