Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 仅对匹配模式的目录进行tarball_Unix_Archive_Tar - Fatal编程技术网

Unix 仅对匹配模式的目录进行tarball

Unix 仅对匹配模式的目录进行tarball,unix,archive,tar,Unix,Archive,Tar,我有一个父目录,其中有许多子文件夹,每个子文件夹中都有一个名为“start”的目录。我想从父目录创建一个tarball,让它只包含名为“start”的目录,但要维护父目录子结构。如何执行此操作?假设Bash,您可以使用扩展的globbing仅选择所需的子目录 示例:让我们创建一个虚拟目录层次结构 $ mkdir -p test/{top,bottom}/{start,finish}/{one,two} $ find test test test/bottom test/bottom/finish

我有一个父目录,其中有许多子文件夹,每个子文件夹中都有一个名为“start”的目录。我想从父目录创建一个tarball,让它只包含名为“start”的目录,但要维护父目录子结构。如何执行此操作?

假设
Bash
,您可以使用扩展的globbing仅选择所需的子目录

示例:让我们创建一个虚拟目录层次结构

$ mkdir -p test/{top,bottom}/{start,finish}/{one,two}
$ find test
test
test/bottom
test/bottom/finish
test/bottom/finish/one
test/bottom/finish/two
test/bottom/start
test/bottom/start/one
test/bottom/start/two
test/top
test/top/finish
test/top/finish/one
test/top/finish/two
test/top/start
test/top/start/one
test/top/start/two
现在,要创建仅包含目录
start
及其内容的tar存档:

$ tar cvf test.tar test/**/start
a test/bottom/start
a test/bottom/start/one
a test/bottom/start/two
a test/top/start
a test/top/start/one
a test/top/start/two
$ 
请注意,必须启用扩展全局绑定才能使用此解决方案

$ shopt extglob
extglob         on
如果未启用,请使用

$ shopt -s extglob

假设
Bash
,您可以使用扩展的globbing仅选择所需的子目录

示例:让我们创建一个虚拟目录层次结构

$ mkdir -p test/{top,bottom}/{start,finish}/{one,two}
$ find test
test
test/bottom
test/bottom/finish
test/bottom/finish/one
test/bottom/finish/two
test/bottom/start
test/bottom/start/one
test/bottom/start/two
test/top
test/top/finish
test/top/finish/one
test/top/finish/two
test/top/start
test/top/start/one
test/top/start/two
现在,要创建仅包含目录
start
及其内容的tar存档:

$ tar cvf test.tar test/**/start
a test/bottom/start
a test/bottom/start/one
a test/bottom/start/two
a test/top/start
a test/top/start/one
a test/top/start/two
$ 
请注意,必须启用扩展全局绑定才能使用此解决方案

$ shopt extglob
extglob         on
如果未启用,请使用

$ shopt -s extglob

成功了!谢谢你做到了!非常感谢。