第8周
麒麟系统压缩解压命令
一、tar(最常用,保留权限,运维首选)
参数说明:
-c创建包;-x解压;-t查看包内文件-zgzip(tar.gz);-jbz2(tar.bz2);-Jxz(tar.xz)-v显示过程;-f指定文件名;-C解压到指定目录
# 1. 压缩 tar.gz
tar -zcvf test.tar.gz test/
# 2. 解压 tar.gz
tar -zxvf test.tar.gz
# 3. 查看包内容
tar -ztvf test.tar.gz
# 4. 解压到指定目录
tar -zxvf test.tar.gz -C /home/kylin/tmp
# tar.bz2
tar -jcvf test.tar.bz2 test/
tar -jxvf test.tar.bz2
# tar.xz
tar -Jcvf test.tar.xz test/
tar -Jxvf test.tar.xz
# 只打包不压缩(tar)
tar -cvf test.tar test/
tar -xvf test.tar
二、zip /unzip(Windows 互通,重点:中文乱码)
# 压缩文件夹(-r 递归)
zip -r test.zip test/
# 解压
unzip test.zip
# 解压到指定目录
unzip test.zip -d ./out
# 查看压缩包内文件
unzip -l test.zip
# 【重点】Windows过来的zip,中文乱码,GBK编码解压
unzip -O GBK test.zip
# 带密码解压
unzip -P 123456 test.zip
-O GBK大写 O,解决 Windows 压缩中文文件名乱码统信软件-...
三、7z(高压缩率,推荐)
命令:7z / 7za
# 压缩 a=add
7z a test.7z test/
# 加密压缩(回车后输入密码)
7z a -p test.7z test/
# 解压 x(保留目录结构,推荐)
7z x test.7z
# e 解压,不保留目录,全部平铺
7z e test.7z
# 查看包内容
7z l test.7z
四、rar(默认不自带,需要单独装 unrar)
# 解压rar(保留目录)
unrar x test.rar
# 解压,平铺所有文件
unrar e test.rar
# 查看
unrar l test.rar
五、gzip /bzip2(单文件压缩,不打包文件夹)
gzip test.txt # 压缩,源文件消失
gzip -k test.txt # -k 保留原文件
gunzip test.txt.gz
bzip2 test.txt
bunzip2 test.txt.bz2
六、常见坑
- zip 中文乱码:
unzip -O GBK xxx.zip - tar 不要把 - f 放前面,
-f必须在最后 - 分卷 7z:直接解压第一个
xxx.001,7z x xxx.001 - 服务器无图形,优先 tar、7z
七、小技巧
静默解压(不输出日志)
unzip -q test.zip
tar -zxf test.tar.gz
浙公网安备 33010602011771号