recursively use scp but excluding some folders

后端 未结 6 634
庸人自扰
庸人自扰 2021-01-30 12:25

Assume there are some folders with these structures

/bench1/1cpu/p_0/image/
/bench1/1cpu/p_0/fl_1/
/bench1/1cpu/p_0/fl_1/
/bench1/1cpu/p_0/fl_1/
/bench1/1cpu/p_0         


        
6条回答
  •  后悔当初
    2021-01-30 13:15

    Although scp supports recursive directory copying with the -r option, it does not support filtering of the files. There are several ways to accomplish your task, but I would probably rely on find, xargs, tar, and ssh instead of scp.

    find . -type d -wholename '*bench*/image' \
    | xargs tar cf - \
    | ssh user@remote tar xf - -C /my/dir
    

    The rsync solution can be made to work, but you are missing some arguments. rsync also needs the r switch to recurse into subdirectories. Also, if you want the same security of scp, you need to do the transfer under ssh. Something like:

    rsync -avr -e "ssh -l user" --exclude 'fl_*' ./bench* remote:/my/dir
    

提交回复
热议问题