I have this problem, I have an Ubuntu server (SSH enabled on port 4444). Inside this server there's a directory called /folder/a/, this directory literally contains millions of small size text files.

What i want to do is to find several thousands of files from those millions of files and copy or transfer those files to my local pc, i.e. using find command. When using scp or cpio it won't work properly.

Do you have any suggestion how to do this from my local pc, i.e not from running ssh terminal on my remote server.

  • It's possible to run ssh on the local PC with a command which is executed on the remote PC, and whose output is redirected back to the local PC. You can use this technique to execute find to build a list of files which is fed into tar. The output of tar is directed to the standard output of the ssh command. Note that the finding and archiving happens on the remove (server) PC. If that's not an option, you'd have to mount the remote directory into your local PC, which you can do with a network filesystem such as NFS, or even with SSH itself. – Emmanuel Rosa Feb 10 '19 at 5:20
  • i know but, i want to do something like this (from local pc) ssh -p 4444 username@ "cd /folder && find ./a/ -xdev -name 'X*.somename.*' -mtime +0 -mtime -7 -print | head -15000" but the problem is i dont know how to pipe or combine those find command with scp or rsync or even tar then transfer it to my local pc directory – xcode Feb 10 '19 at 5:26
rsync -e 'ssh -p 4444' -a --include="pattern you want" --exclude="*" $S:/folder/a ~/copy


ssh -p 4444 $S "find /folder/a -name 'pattern you want' | tar -cO -T -" > ~/copy.tar


rsync -e 'ssh -p 4444' -a --files-from=<(ssh -p 444 $S find /folder/a -name 'pattern you want') $S:/folder/a ~/copy
| improve this answer | |
  • thanks, how to combine rsync command with find command, since i want to use find with many of its options? – xcode Feb 10 '19 at 5:42
  • @xcode added to answer – user1133275 Feb 10 '19 at 5:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.