仅压缩目录中的文件
如果我有一个包含一堆图像的文件夹,如何只压缩图像而不压缩图像的文件夹结构,而无需将 CD 放入图像目录?
tar czf images.tgz /path/to/images/*
现在,当提取 images.tgz 时,提取的内容是 /path/to/images/...
我如何只能将图像包含到 tgz 文件中(而不是导致图像的三个文件夹)?
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/*
Now when images.tgz is extracted, the contents that are extracted are /path/to/images/...
How I can only have the images included into the tgz file (and not the three folders that lead to the images)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道您可以在解压时使用
--strip-components
虽然我不确定这在创建时是否也有效。也许迭代文件夹结构,然后通过 stdout/stdin 将结果按顺序传送到 tar? (使用
cat
或类似的?)IANA Linux 专家很担心我只能在此时进行理论分析而不是提供硬代码,但你现在让我想知道......I know you can use
--strip-components
when untarring although I'm not sure if this would also work when creating.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...