I'm trying to make a script that will run in cron, that will search a path for specific file name. In the path there might be more folders with that same file name. If found and they are newer than 2 days, rsync the parent folder and all content. This part works but only syncs "filename.txt" that is newer than 2 days and nothing else:

find /path/ -name "filename.txt" -type f -mmin -$((60*48)) -exec rsync --ignore-exsiting -az --log-file=/path/ {} /source /destination \;

I'm assuming by parent folder you just mean the folder with filename.txt.

You can get find to print this folder name with -printf '%h\n' instead of the -exec. You can pipe this into a shell loop or xargs for example:

find /path/ -name "filename.txt" -type f -mtime -2 -printf '%h\n' |
  xargs -i rsync ... {} /destination \;

I think you need to add -R to your rsync, else all the directories will be superimposed at the destination.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.