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.