I want to run rsync on server A to copy all files from Server B when they are newer than 7 days.

find . -mtime -7

I don't want to delete the files on Server B.

  • b) how often do you run rsync?
    – phresnel
    Jun 14, 2011 at 13:53

2 Answers 2


This should get you underway in a solid way

rsync -RDa0P \
    --files-from=<(find sourcedir/./ -mtime -7 -print0) \
    . user@B:targetdir/

This copies device nodes, permissions, timestamps. I'm pretty sure the -H option won't be accurate with --files-from

  • 30
    To set that as a remote filter: rsync -avn --files-from=<(ssh user@A 'find /path/on/A/ -mtime -7 -type f -exec basename {} \;') user@A:/path/on/A/ user@B:targetdir
    – cybertoast
    Aug 22, 2014 at 16:04
  • 1
    I want to add a correction for cybertoast's comment. Perhaps the context on his different from mine but I was trying to simple extract files from a remote server given the time criteria. So, server A is my destination and server B is my source, then: rsync -avn --files-from=<(ssh user@A 'find /path/on/A/ -mtime -7 -type f -exec basename {} \;') user@B:/ /path/in/server/A Notice there's only a leading / for source. The --files-from takes care of the relative path for you. If you have doubts use man rsync and see the --files-from section.
    – eco
    Oct 27, 2016 at 17:09
  • @cybertoast What does basename mean in your command? Can you explain please? Jun 29, 2017 at 19:21
  • @KematRochi - "basename, dirname -- return filename or directory portion of pathname". Hope that helps.
    – cybertoast
    Jun 29, 2017 at 23:40
  • @KematRochi Yeah, I don't see the point of basename. What if there are multiple, identically named files with different modification times? This command as it stands will transfer them all, regardless of their modification times.
    – Geremia
    Jan 7, 2023 at 20:06

I wrote this script based on cybertoast's comment to sync from a remote server to local.

You can call the script with ./script.sh 3 or ./script.sh 3 dry for a dry run.


if [[ -z $TIME ]]; then
  echo "Error: no time argument."
  echo "Please enter the number of days to sync."
  exit 1

if [[ $DRYRUN = "dry" ]]; then
  echo "Dry run initiated..."

rsync -avz $DRYRUNCMD --files-from=<(ssh \
    user@remote "find path/to/data/ \
    -mtime -$TIME ! -name *.mkv -type f \
    -exec ls $(basename {}) \;") \
  user@remote:. .

You must log in to answer this question.

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