从 tar.gz 中提取特定文件夹到特定目录 [英] Extract a specific folder to specific directory from a tar.gz

查看:35
本文介绍了从 tar.gz 中提取特定文件夹到特定目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并找到了我想要的两个部分的方法,但没有什么可以让你完全做到这一点......

I have searched and found how to the two portions of what I want but nothing that would allow you to do it in whole....

我想要做的是将特定文件夹从 tar.gz 解压缩到另一个文件夹中的另一个文件夹,该文件夹与 tar.gz 中的路径不同.

What I would like to do is extract a specific folder from a tar.gz to another folder in a different path that how it is in the tar.gz.

例如:

  • 我的backup.tar.gz文件中的目录路径是:a/b/c/d(d是我的主目录,里面有很多其他的)

  • Directory path in my backup.tar.gz file is: a/b/c/d (d is my main with many others inside)

我想在这个不同的服务器路径中将目录d"解压到m"中:a/b/m

I want to unpack directory 'd' into 'm' inside this different server path: a/b/m

如果我尝试这个代码:tar -xzf backup.tar.gz -C a/b/m

If I attempt this code: tar -xzf backup.tar.gz -C a/b/m

** 文件夹结构看起来像:a/b/m/a/b/c/d 但我希望它看起来像 a/b/m+d 以便我存档中的所有主要文件/文件夹'd' 路径以 'm' 路径结束

** The folder structure looks like: a/b/m/a/b/c/d but I would like it to look like a/b/m+d so that all my main files/folders in the archived 'd' path ends up in the 'm' path

非常感谢任何帮助.

谢谢!

推荐答案

好的,我想通了!

基本上我可以使用strip 命令删除x 个前导目录.在这种情况下,我的命令将如下所示:

Basically I can just use the strip command to remove the x number of leading directories. In this case, my command would look like this:

tar -xzf backup.tar.gz --strip-components=3 -C a/b/m

tar -xzf backup.tar.gz --strip-components=3 -C a/b/m

在将其解压缩到 desctination 目录之前,它从我的存档 (backup.tar.gz : a/b/c/d) 中删除了前三个路径目录.

That removed the first three path directories from my archive (backup.tar.gz : a/b/c/d) before extracting it to the desctination directory.

现在看起来像这样:a/b/m+d

Now it looks like this: a/b/m+d

这篇关于从 tar.gz 中提取特定文件夹到特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆