vieyahn2017 / shellv

shell command test and study
4 stars 1 forks source link

12.24 tar命令解压时如何去除目录结构及其解压到指定目录 (--strip-components N) #63

Open vieyahn2017 opened 4 years ago

vieyahn2017 commented 4 years ago

tar命令解压时如何去除目录结构及其解压到指定目录 (--strip-components N)

vieyahn2017 commented 4 years ago

tar命令解压时如何去除目录结构及其解压到指定目录 (--strip-components N) 去除目录结构加上 --strip-components N

如: 压缩文件eg.tar 中文件信息为 src/src/src/eg.txt

运行 tar -xvf eg.tar --strip-components 1

结果:src/src/eg.txt

如果运行 tar -xvf eg.tar --strip-components 3

解压结果为: eg.txt

在解压的时候,如果想指定解压目录,可以加参数-C 目标目录

如: 如我们解压eg.tar, 该文件在/data/src下面,如果需要将基解压到/data/dst目录下面,我们可以在/data/dst目录下,运行 tar -xvf /data/src/eg.tar 也可以在/data/src目录下面运行

tar -xvf eg.tar -C /data/dst

vieyahn2017 commented 4 years ago

https://www.cnblogs.com/zhangmingcheng/p/7150888.html