find and rsync?

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x