Unix 仅对匹配模式的目录进行tarball
我有一个父目录,其中有许多子文件夹,每个子文件夹中都有一个名为“start”的目录。我想从父目录创建一个tarball,让它只包含名为“start”的目录,但要维护父目录子结构。如何执行此操作?假设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
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
成功了!谢谢你做到了!非常感谢。