linux解压缩
2019-11-24 本文已影响0人
夜空痕
解压缩
工作中,有两种常用的解压缩zip和unzip和tar格式的;
首先在这里介绍下tar格式
tar解压缩命令,tar解压缩命令可以处理tar,tar.gz,tgz,tar.bz2后缀的文件
涉及的参数:
- -c 建立新的压缩文件
- r 添加文件到已经压缩的文件
- u 添加改变了和现有的文件到已经存在的压缩文件
- x 从压缩的文件中提取文件
- t 显示压缩文件的内容
- z 支持gzip解压文件
- j 支持bzip2解压文件
- v 显示操作过程
- k 保留源有文件不覆盖
- C 切换到指定目录
- f 指定压缩文件
常用的组合命令:
tar -zcvf xxx.tar.gz file1 file2 # 将文件压缩为.tar.gz
tar -xvf xxx.tar.gz #解压文件到当前文件夹
tar -xvf xxx.tar.gz -C dir # 将文件解压到指定文件夹,在实际中通常使用的是这种
例如:
root@JD:/home/yj/test# tar -zcvf logs.tar.gz test1.log test2.log test.log
test1.log
test2.log
test.log
root@JD:/home/yj/test# ls
logs.tar.gz test1.log test2.log test.log z
root@JD:/home/yj/test# ls
logs.tar.gz test1.log test2.log test.log z
root@JD:/home/yj/test# rm -rf test1.log test.log test2.log z
root@JD:/home/yj/test# ls
logs.tar.gz
root@JD:/home/yj/test# tar -xvf logs.tar.gz
test1.log
test2.log
test.log
root@JD:/home/yj/test# ls
logs.tar.gz test1.log test2.log test.log
uzip和zip主要用于处理zip包
zip -r test.zip test/ #将test目录下的文件压缩到test.zip文件夹
zip -rj test.zip test/ #打包test目录下文件,且压缩包不带test目录
unzip -o test.zip -d dir #讲test.zip解压到dir目录