Long time reader, first time poster.

I'm trying to rsync the latest few log files from a remote server to my laptop. I've gotten close with this:

ssh -qx [email protected] "cd /path/to/logs && find . -mtime -1 -print0" | rsync --from0 --files-from=- -avHS "[email protected]:/path/to/logs/" .

But that syncs all the files from the past day, which is too many. Ideally I'd like to just download the last half dozen or so files. I know this will list the latest 6 files:

ls -t|head -6

But I'm not sure how to use these two bits of info together (if it's even possible) to solve my problem. Thanks in advance!

  • did you try ssh -qx [email protected] " ls -t /path/to/logs | head -6 " | rsync.... ?
    – Putnik
    Mar 17, 2018 at 7:35
  • Amazing, thank you! I played with it and this worked: ssh -qx [email protected] "ls -t /path/to/logs | head -6" | rsync --files-from=- -avHS [email protected]:/path/to/logs/ .
    – john
    Mar 17, 2018 at 16:12
  • 1
    I've converted my comment to answer, please accept if it works for you.
    – Putnik
    Mar 18, 2018 at 7:22

1 Answer 1



ssh -qx [email protected] "ls -t /path/to/logs | head -6" | rsync --files-from=- -avHS [email protected]:/path/to/logs/ .
  • 1
    Thanks! The exact syntax that worked for me was: ssh -qx [email protected] "ls -t /path/to/logs | head -6" | rsync --files-from=- -avHS [email protected]:/path/to/logs/ .
    – john
    Mar 19, 2018 at 18:31

You must log in to answer this question.

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