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

前端 未结 9 1262
醉酒成梦
醉酒成梦 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:30

    If you indeed wanna use scp, there's a indirect way.Say we want to copy all .jpg file under local folder '/src' to folder '/dst' in remote server 10.1.1.2:

    #make a clean temp folder
    mkdir /tmp/ttt
    #copy all .jpg file and retain folder structure as-is
    find /src -type f -name *.jpg -exec cp --parents \{\} /tmp/ttt \;
    #copy to remote target folder as-is and retain original time attributes
    scp -rp /tmp/ttt/* 10.1.1.2:/dst
    #if copy ok, remove temp folder
    rm -rf /tmp/ttt
    

提交回复
热议问题