目录
tar
# 压缩文件有时候我们也叫做归档文件
#但是归档和压缩有一些区别,归档只是将多个文件捆绑成一个文件,
并没有压缩,而压缩才是将大小压缩的更小。
#Linux最常用的压缩和解压指令是:
tar:能够解压的文件格式是xx.tar.gz
压缩:tar -zcf 压缩包路径 目标1 目标2 目标3 ...
解压:tar -zxf 解压路径
------------------------------------------------------------
压缩和解压文件
[root@localhost ~]# ls
123.txt 4.txt a.txt c.txt jaden.txt
[root@localhost ~]# tar -zcf jaden.tar.gz services #压缩文件
[root@localhost ~]# tar -zxf jaden.tar.gz # 解压文件
#归档,但是不压缩
tar -cf
[root@localhost ~]# cp /etc/services ./shike # 再拷贝一个services文件过来
#查看压缩包内容
[root@localhost ~]# tar -tf 3.tar.gz
gzip
打包和压缩
gzip
#压缩文件,会自动删除原文件,和tar不同,tar会留着原文件
[root@localhost ~]# gzip services
[root@localhost ~]# ls -lh
# 解压,会自动删除原压缩包
[root@localhost ~]# gzip -d services.gz
[root@localhost ~]# ls -lh
#压缩多个文件,每一个文件产生一个单独的压缩包
[root@localhost ~]# gzip services shike
#解压缩
[root@localhost ~]# gzip -d services.gz shike.gz
zip
#压缩
zip
[root@localhost ~]# zip -r 1.zip services shike #会保留原文件
------------------------------------------------------------------
#解压
unzip
例子1: # 解压之前先把原文件删掉,以免冲突
[root@localhost ~]# unzip 1.zip
RAR
#解压rar包#需要安装软件
yum install epel-release -y
yum install unar -y
#再进行解压
unar -o 解压路径 被解压文件路径
例如:
unar -o /opt 456.rar