仅对目录中的文件进行tarring [英] Tarring only the files of a directory
问题描述
如果我有一个包含一堆图像的文件夹,我如何只压缩图像而不是压缩导致图像的文件夹结构,而不必将 CD 放入图像目录?
If I have a folder with a bunch of images, how can I tar ONLY the images and not the folder structure leading to the images without having to CD into the directory of images?
tar czf images.tgz/path/to/images/*
tar czf images.tgz /path/to/images/*
现在提取images.tgz时,提取的内容是/path/to/images/...
Now when images.tgz is extracted, the contents that are extracted are /path/to/images/...
我如何只能将图像包含在 tgz 文件中(而不是导致图像的三个文件夹)?
How I can only have the images included into the tgz file (and not the three folders that lead to the images)?
推荐答案
我知道你可以在解压时使用 --strip-components
虽然我不确定这是否也适用于创建.
I know you can use --strip-components
when untarring although I'm not sure if this would also work when creating.
也许遍历文件夹结构,然后通过 stdout/stdin 将结果按顺序传送到 tar?(使用 cat
或类似的?)IANA Linux 专家太害怕了,我现在只能理论而不是提供硬代码,但你现在让我想知道......
Perhaps iterate through a folder structure and then pipe the results via stdout/stdin to tar sequentially? (with cat
or similar?) IANA Linux Expert so afraid I can only theorise versus provide hard code at this second, you've got me wondering now though...
这篇关于仅对目录中的文件进行tarring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!