fileshellfilterdirectoryscp

How to filter files when using scp to copy dir recursively?


I need to copy all the .class files from server to local with all dir reserved. e.g. server:/usr/some/unknown/number/of/sub/folders/me.class will be /usr/project/backup/some/unknown/number/of/sub/folders/me.class the problem is, there are many other useless files such as .svn-base files that i don't want. how can i filter them so I only scp .class files?


Solution

  • I'd probably recommend using something like rsync for this due to its include and exclude flags, e.g:-

    rsync -rav -e ssh --include '*/' --include='*.class' --exclude='*' \
    server:/usr/some/unknown/number/of/sub/folders/ \ 
    /usr/project/backup/some/unknown/number/of/sub/folders/
    

    Some other useful flags: