击:递归复制命名的文件,preserving文件夹结构 [英] Bash: Copy named files recursively, preserving folder structure

查看:143
本文介绍了击:递归复制命名的文件,preserving文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望:

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

将在目的地目录产生一个对称结构:

would yield a symmetrical structure in the destination dir:

/tmp
|
+-- package
    |
    +-- src
    |   |
    |   +-- prog.js
    |
    +-- images
        |
        +-- icon.jpg

但相反,这两个文件复制到/ tmp目录/包。平面复制。 (这是OSX)。

but instead, both of the files are copied into /tmp/package. A flat copy. (This is on OSX).

有一个简单的bash的功能,我可以用它来复制所有文件,包括通配符指定的文件(例如SRC / *。JS)到目标目录中应有的地位。好像有点为每个文件,运行的mkdir -p $(目录名称$文件); CP$文件$(目录名称$文件),但也许一个命令。

Is there a simple bash function I can use to copy all files, including files specified by wildcard (e.g. src/*.js) into their rightful place within the destination directory. A bit like "for each file, run mkdir -p $(dirname "$file"); cp "$file" $(dirname "$file")", but perhaps a single command.

<一个href=\"http://www.linuxquestions.org/questions/linux-newbie-8/how-to-do-recursive-file-copy-of-directory-for-specific-files-199134/\">This是一个相关的线程,这表明这是不可能的。的作者的解决方案,对我来说并不那么有用,但因为我想简单地提供文件,通配符与否的名单,并有所有的人都复制到目标目录。 IIRC MS-DOS XCOPY做到这一点,但似乎没有类似的CP。

This is a relevant thread, which suggests it's not possible. The author's solution isn't so useful to me though, because I would like to simply provide a list of files, wildcard or not, and have all of them copied to the destination dir. IIRC MS-DOS xcopy does this, but there seems to be no equivalent for cp.

推荐答案

您是否尝试过使用--parents选项?我不知道,如果OS X支持,但在Linux上工作。

Have you tried using the --parents option? I don't know if OS X supports that, but that works on Linux.

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

如果没有在OS X上工作,尝试

If that doesn't work on OS X, try

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

为AIF建议。

这篇关于击:递归复制命名的文件,preserving文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆