Quantcast
Channel: How do i copy N images from server to my local machine using rsync? - Server Fault
Viewing all articles
Browse latest Browse all 4

Answer by Gerald Schneider for How do i copy N images from server to my local machine using rsync?

$
0
0

rsync has no way of listing and restricting to files on the remote server. So you have to build a list of files beforehand. You can do that, for example, using find and head:

find /path/to/dir -type f |head -n 100'

will return the first 100 files found.

rsync has the parameter --files-from, which allows you to read the list of files to copy from a file. It can even read that list from the remote server. So, you could write that list of files into a file, and provide it to rsync.

But you can actually do all that with a single command:

ssh source 'find /path/to/dir -type f |head -n 100' | rsync --files-from - source:/ /path/to/local/dir

This will connect with ssh to the server source and return the first 100 files from the search result. This result is then piped into rsync. Using - as the value for the parameter --files-from tells rsync to read that 'file' from stdin instead of an actual file. Then you provide the source and the target as usual.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>