• Dir1
    • DirA
    • DirB
      • File1
      • File2
  • Dir2


  • Dir1

I want all directories and files in REMOTE Dir1 that are older than 2days to rsync to local directory Dir1 with delete option. Not even certain if I could run it on local and pull from remote, as how would I obtain the list of files? Yes, I have seen some answers but I do not see how this would work.

  • Can't you just pull all files over and then delete the old ones locally? That would be much easier. Timestamps are transferred if you use the --archive option.
    – Kusalananda
    Oct 6, 2023 at 19:39

1 Answer 1


Provided you can guarantee that file names don't contain spaces or other complicating characters you can embed find into the rsync command. However, my recommendation would be to run the find remotely as this avoids any of the aforementioned complications:

ssh -n remoteHost find /path/to/source -type f -mtime +2 -print0 |
    rsync --dry-run -av --from0 --files-from - remote host:/ /path/to/target

Test, and when you're happy with the set of matched files, remove --dry-run

You must log in to answer this question.

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