Linux 压缩与解压缩命令 tar gzip zip rar 详解

目录

tar

gzip

zip

RAR


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  
相关推荐
w***Q35023 分钟前
Git工作流自动化
运维·git·自动化
qq_4017004130 分钟前
嵌入式用Unix时间的优势及其C语言转换
服务器·c语言·unix
xu_yule3 小时前
Linux_12(进程信号)内核态和用户态+处理信号+不可重入函数+volatile
linux·运维·服务器
虾..3 小时前
Linux 环境变量&&进程优先级
linux·运维·服务器
i***t9193 小时前
Linux下MySQL的简单使用
linux·mysql·adb
偶像你挑的噻3 小时前
11-Linux驱动开发-I2C子系统–mpu6050简单数据透传驱动
linux·驱动开发·stm32·嵌入式硬件
稚辉君.MCA_P8_Java4 小时前
DeepSeek 插入排序
linux·后端·算法·架构·排序算法
数据库学啊5 小时前
团队小希望运维简单,时序数据库选型有什么推荐?
运维·数据库·时序数据库
霍格沃兹软件测试开发5 小时前
Playwright MCP浏览器自动化指南:让AI精准理解你的命令
运维·人工智能·自动化
郝学胜-神的一滴6 小时前
Linux命名管道:创建与原理详解
linux·运维·服务器·开发语言·c++·程序人生·个人开发