tar解压到指定目录并且重名原始目录名

时间:2023-05-09 17:21:04 买帖  | 投诉/举报

篇首语:本文由小编为大家整理,主要介绍了tar解压到指定目录并且重名原始目录名相关的知识,希望对你有一定的参考价值。

1.wget 命令下载文件weget -O 重命名下载文件wget -O mysql57.tar.gz http://oss.aliyuncs.com/aliyunecs/onekey/mysql/mysql-5.7.22-linux-glibc2.12-x86_64 .tar.gz2.tar解压文件[[email protected] opt]$tar -zxvf mysql57.tar.gz[[email protected] opt]$ lsmysql-5.7.22-linux-glibc2.12-x86_64 结果不是mysql57而是源码目录原始结构3.解决方法[[email protected] opt]$mkdir ./mysql57 && tar -zxvf mysql-5.6.15.tar.gz -C ./mysql57 --strip-components 1备注:-C表示解压指定目录如:当前目录mysql57下--strip-components N 表示删除目录结构(n=1表示删除最外【或前1】层结构)实例1:test.tar.gz中包含目录123/test/conf.xml,只要conf.xml文件,就要去除文件名前2层路径#新建目录并创建conf.xml文件[[email protected] soft]$ mkdir -p 123/test000123 && touch 123/test000123/conf.xml#创建压缩文件[[email protected] test000123]$ tar -czvf test.tar.gz /home/cqs/soft/123/test000123/conf.xml [[email protected] test000123]$ lsconf.xml test.tar.gz #解压文件[[email protected] test000123]$ tar -xzvf test.tar.gz home/cqs/soft/123/test000123/conf.xml[[email protected] test000123]$ lsconf.xml home test.tar.gz结果目录:home/cqs/soft/123/test000123/conf.xml#tar -zxvf test.tar.gz --strip-components 2 结果目录:soft/123/test000123/conf.xml实例2:去除一层#tar -zxvf test.tar.gz --strip-components 1 结果目录:cqs/soft/123/test000123/conf.xml

以上是关于tar解压到指定目录并且重名原始目录名的主要内容,如果未能解决你的问题,请参考以下文章