不使用顶级目录解压

Edg*_*ase 4 command-line tar

我有一个 tar (websites.tgz),其中包含一堆以“htdocs”开头的 Drupal 网站

我需要把它们解压成

/local/htdocs/web1
/local/htdocs/web2
Run Code Online (Sandbox Code Playgroud)

等等。但是由于权限,我无法将 website.tgz 文件放在 /local 中并向下提取。它目前在我的主目录中。如何解压 /local/htdocs 下的内容,而不包括顶级 htdocs 目录?

我试图避免:

/local/htdocs/htdocs/web1
/local/htdocs/htdocs/web2.
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助。

jor*_*anm 5

您可以-C在某些 tar 实现中使用该选项来指定提取的基本路径。以下内容适用于您的示例。

tar -xvz -C /local -f websites.tgz
Run Code Online (Sandbox Code Playgroud)

或者,如果您tar没有-z-C选项:

gunzip < websites.tgz | (cd /local && tar xvf -)
Run Code Online (Sandbox Code Playgroud)