Bash: Copy named files recursively, preserving folder structure

后端 未结 6 767
借酒劲吻你
借酒劲吻你 2020-11-29 17:48

I was hoping:

cp -R src/prog.js images/icon.jpg /tmp/package

would yield a symmetrical structure in the destination dir:

/t         


        
6条回答
  •  既然无缘
    2020-11-29 18:31

    Alternatively, if you're old-school, use cpio:

    cd /source;
    find . -print | cpio -pvdmB /target
    

    Clearly, you can filter the file list to your heart's content.

    The '-p' option is for 'pass-through' mode (as against '-i' for input or '-o' for output). The '-v' is verbose (list the files as they're processed). The '-m' preserves modification times. The '-B' means use 'big blocks' (where big blocks are 5120 bytes instead of 512 bytes); it is possible it has no effect these days.

提交回复
热议问题