36

I want to be able to search for files over 14 days and over 10k and than rsync those found files to a destination.

Is there a way to combine these two commands?

find ./ -mtime +14 -size +10k 
rsync --remove-sent-files -avz /src /dest

1 Answer 1

52

You can send the output of find into rsync using one of the options outlined below.

Method #1

These 2 options are very similar, they both assume you're changing directories to some location and then running the find command from there.

$ rsync -avz --remove-sent-files \
        --files-from=<(find ./ -mtime +14 -size +10k) ./ /dest

You can also use a pipe to feed the list in:

$ find ./ -mtime +14 -size +10k -print0 \
        | rsync -av --files-from=- --from0 ./ /dest

Method #2

This method can be run from anywhere.

$ find /src/dir/ -mtime +14 -size +10k -printf %P\\0 \
        | rsync -av --files-from=- --from0 /src/dir/ /dst/dir/
  • printf %P: File's name with the name of the command line argument under which it was found removed. This way, you can use any src directory, no need to cd into your src directory first.

References

2
  • 1
    This is another working example rsync -haviHn --stats --progress --files-from=<(find /mnt/my-files -mtime 0 -printf "%p\n") / /mnt/backup-disk/ Find will return an absolute path so you need to set / as the copy source
    – nick fox
    Commented Dec 23, 2020 at 20:35
  • How to apply the above for photos, with the date the photo was taken (via EXIF / meta data) ? E.g., utilizing identify -verbose IMG_20200430_113445.jpg | grep -i date and exif:DateTime. Commented Feb 19, 2023 at 20:25

You must log in to answer this question.

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