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

前端 未结 9 1411
醉酒成梦
醉酒成梦 2021-01-29 20:00

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/proj

9条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 20:35

    Since you can scp you should be ok to ssh,
    either script the following or login and execute...

    # After reaching the server of interest
    cd /usr/some/unknown/number/of/sub/folders
    tar cfj pack.tar.bz2 $(find . -type f -name *.class)
    

    return back (logout) to local server and scp,

    # from the local machine
    cd /usr/project/backup/some/unknown/number/of/sub/folders
    scp you@server:/usr/some/unknown/number/of/sub/folders/pack.tar.bz2 .
    tar xfj pack.tar.bz2
    

    If you find the $(find ...) is too long for your tar change to,

    find . -type f -name *.class | xargs tar cfj pack.tar.bz2
    

    Finally, since you are keeping it in /usr/project/backup/,
    why bother extraction? Just keep the tar.bz2, with maybe a date+time stamp.

提交回复
热议问题