简体   繁体   English

当前目录中的Tar 100目录

[英]Tar 100 Directories within Current Directory

I am attempting to tar 100 directories within a certain directory to a tar file, but I do not want to add more than 100 of these directories to the file. 我试图将某个目录中的100个目录压缩到tar文件中,但是我不想将这些目录中的100个以上添加到该文件中。 For example, the current structure of the directories is like so 例如,目录的当前结构如下所示

.../v0.0/category_name/edf/001/00000010/s01_2012_03_01

Each of these directories has a different number of files in it, and I would like these to be included in the tar as well. 每个目录中都有不同数量的文件,我也希望这些文件也包含在tar中。 What I would like it to do is tar 100 directories with different ../00000010/.. portions of the path. 我想做的是tar 100目录,其中路径的../00000010/..部分不同。 In the end, it might end up creating a tar file with the following structure: 最后,它可能最终会创建具有以下结构的tar文件:

.../v0.0/category_name/edf/001/00000010/s01_2012_03_01/file.txt
.../v0.0/category_name/edf/001/00000010/s01_2012_03_01/file2.txt
.../v0.0/category_name/edf/001/00000010/s02_2012_03_01/file.txt
.../v0.0/category_name/edf/001/00000015/s01_2012_03_01/file.txt
.../v0.0/category_name/edf/004/00000100/s01_2012_03_01/file.txt

Consider the 00000010 portion of the path the directory that represents a "patient". 考虑代表“患者”的目录的路径的00000010部分。 All of the patient's files under his/her directory should be included in the tar. 患者目录下的所有患者文件均应包含在tar中。 There should be 100 different patients tarred to the file, so if the first patient was 00000001 and the hundredth patient was 00000100 , the structure might look something like this. 该文件应包含100个不同的患者对象,因此,如果第一个患者为00000001而第100个患者为00000100 ,则结构可能看起来像这样。

.../v0.0/category_name/edf/001/00000001/s01_2012_03_01/file.txt
.../v0.0/category_name/edf/001/00000001/s01_2012_03_01/file2.txt
.../v0.0/category_name/edf/001/00000001/s02_2012_03_01/file.txt
.../v0.0/category_name/edf/001/00000002/s01_2012_03_01/file.txt
.../v0.0/category_name/edf/004/00000003/s01_2012_03_01/file.txt
...
.../v0.0/category_name/edf/001/00000100/s01_2012_03_01/file.txt
.../v0.0/category_name/edf/004/00000100/s02_2012_03_01/file.txt

This is just an example, and the patient directories will not be numbered in this exact way. 这仅是示例,患者目录将不会以这种确切方式编号。

如果我正确理解了您的问题,则可以这样进行:

find . -type d | head -100 | tar czvf dirs.tgz -T -

Create list of patient directories: 创建患者目录列表:

find -maxdepth 1 . -type d > dirs

Split into chunks of 100: 分成100块:

split -l 100 -d dirs chunk.

Archive directories in each chunk: 在每个块中归档目录:

for f in chunk.* ; do tar -czvf ${f##chunk.}.tar.gz `cat $f` ; done

You will end up with archives called 00.tar.gz , 01.tar.gz , ... each containing 100 directories 您将得到名为00.tar.gz01.tar.gz ,...的存档,每个存档包含100个目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM