There is a collection of .doc files, in addition to other types of files, on a remote server (which supports SCP).I saw a script:FILE=`ssh abc@xyz ls -ht /tmp/*.doc | head -n 1`rsync -avz -e ssh abc@xyz:$FILE .It can copy the latest file from remote server when it use the parameter head -n 1. But I found it cannot copy latest three files from remote server even if it use the parameter head -n 3.
Copying latest three files from remote server
shell script;rsync;head
If abc's login shell on xyz is zsh:ssh abc@xyz 'cd /tmp && tar cf - ./*.doc(.LM-100om[1,3]) | gzip -3' |  gunzip | tar xvf -If it's not zsh (but zsh is installed):ssh abc@xyz cd /tmp && exec zsh -c 'tar cf - ./*.doc(.LM-100om[1,3]) | gzip -3' |  gunzip | tar xvf -In any case, beware that /tmp (or any world-writable directory) is a mine-field. Above, we're careful enough to only select regular files smaller than 100 MiB (with (.LM-100)), and tar will not follow symlinks or read the content of devices or named pipes but there's still a race-condition where someone could enlarge a file to several tebibytes in between that glob being expanded and the tar command being run.And of course, anybody could put malware with a .doc extension in /tmp, so you'd need to treat those download files very carefully.It would be better to do that in private directory instead of /tmp.