Rsync files younger or older than

Today I needed to copy all files from a certain folder, but younger than 1 month  to a remote machine.

I knew how to use find of course… and rsync is pretty easy too… Combining these 2 needs some explanation:

Finding files younger than 31 days is performed like this:

Rsyncing all files from a folder is pretty easy too:

Now, if you would like to rsync only the filers younger thn 31 days from your source folder, you can combine rsync and find in this way:

However… this is not 100 working as intended… This will skip filename with spaces, as the space are not escaped during the rsync…

The solution for this is to split the one liner above into 2 seperate commands again:

1) perform the find, and write the output to a tempfile:

2) perform the rsync with the –from-files parameter:

(do not forget the . in the command to declare a ‘source dir’)

Remark: When using relative paths, you could/should change the /path/to/folder to path/to/folder and put a . instead of a / in your rsync command
E.g. like this: