使用 --strip-components=1 解压 tar 文件

use*_*152 3 linux tar

我有一个 tar 文件,其中有多个文件夹,如下所示:

code.tar
  bin/
    startup.sh
  WebServer/
    appname
    webappname
  Configuration/
    a.properties
    b.properties
Run Code Online (Sandbox Code Playgroud)

如果我解压缩 code.tar,我会得到一个文件夹名称code,其中包含其下的所有文件夹结构,但我想提取其中的内容code.tar并仅获取其下的子文件夹结构(即这些文件夹中的bin/WebServer/configuration/文件)。

当我使用时,tar -xzf code.tar -C <path> --strip-components=1我会获取子文件夹 ie 等的所有内容startup.sh以及appname子文件夹 -

例如,在运行上述命令时,我得到同一级别的所有这些文件夹和文件-

bin/
startup.sh
WebServer/
appname
webappname
Configuration/
a.properties
b.properties
Run Code Online (Sandbox Code Playgroud)

请帮忙

Mur*_*phy 6

你的命令看起来是正确的。

假设您有文件夹“extract”,您要将文件提取到:

tar -xzf code.tar -C extract --strip-components=1
Run Code Online (Sandbox Code Playgroud)

因此,这将截断上层文件夹“code”,并仅提取保留文件文件夹结构的内容。