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

查看:73
本文介绍了从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

该操作从我的档案文件中删除了前三个路径目录(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天全站免登陆