I have bunch of files on the remote server.

I'm not interested in most of them, except for .pl files.

I want to get a copy of these on my local computer.

What is the best way to do this (at the same try preserving its path)?

I'm thinking somewhere along the lines of:

find . -name "*.pl" | xargs scp localuser@localip

Sadly doesn't do the trick. Anyone have better ideas?


$rsync -av --prune-empty-dirs --include-from=filter user@remotesource/ target/

$cat filter

+ *.pl
+ */
- *

edit: typo

  • After a bit of modification, this also works. Now to decide which is the winner... decisions. – denormalizer Oct 13 '10 at 22:42
  • After checking the results, i found the rsync method copied all the .pl files while the find method (for some reason) skipped a substantial number of .pl files. So i have to award the answer to Rosco. – denormalizer Oct 13 '10 at 22:53
  • Even though i chose this as the answer, i find it rather inconvenient to create the extra filter file. I would have leant towards the find method if it did copy all the files. – denormalizer Oct 13 '10 at 22:56

Maybe this?

  find -type d -printf "mkdir %p\n" ;
  find -name "*.pl" -printf "put %p %p\n" ;      
} | sftp localuser@localip
  • Testing this first. Worked. Yay! – denormalizer Oct 13 '10 at 22:22
  • Sorry i can't upvote. i needz more reputation – denormalizer Oct 13 '10 at 22:56
  • @superspace You should mark the answer as "accepted" if it resolved your problem. – jscott Jul 23 '12 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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