一、指定去除目录结构,使用--strip-components N
如:压缩文件 file.tar
中文件信息为 three/two/one/file.txt
1、(去除第一层目录 three
)运行以下命令:
tar -xvf file.tar --strip-components 1
最终结果为:
two/one/file.txt
2、(去除三层目录 three
、two
、one
、)运行以下命令:
tar -xvf file.tar --strip-components 3
解压结果为:
file.txt
二、指定解压到某个目录,使用-C
如:如我们解压 file.tar
,该压缩文件在 /data/src
下面,此时我们需要将其解压到 /data/dst
目录下面
我们可以在任意目录下,运行:
tar -xvf /data/src/file.tar -C /data/dst
也可以在 /data/src
目录下面运行
tar -xvf file.tar -C /data/dst