CentOS Linux教程(9)--使用zip压缩解压文件、目录

文章目录

  • [1. 背景](#1. 背景)
  • [2. 安装zip](#2. 安装zip)
  • [3. 压缩](#3. 压缩)
  • [4. 解压](#4. 解压)
  • [5. 直接压缩目录](#5. 直接压缩目录)
  • [6. 直接解压为目录](#6. 直接解压为目录)

1. 背景

zip也是常用的压缩格式,本节介绍zip压缩解压方法。

2. 安装zip

CentOS并未自带zip,需要安装:

shell 复制代码
[chen@localhost test1]$ sudo yum -y install zip unzip
上次元数据过期检查:0:33:53 前,执行于 2024年09月26日 星期四 22时14分32秒。
软件包 zip-3.0-23.el8.x86_64 已安装。
软件包 unzip-6.0-45.el8_4.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!

3. 压缩

使用zip命令压缩即可:

shell 复制代码
[chen@localhost test1]$ zip all.zip all.tar
  adding: all.tar (deflated 99%)
[chen@localhost test1]$ ls
all.tar  all.zip  a.txt  b.txt

4. 解压

使用unzip解压即可:

shell 复制代码
[chen@localhost test1]$ unzip all.zip all.tar
Archive:  all.zip
  inflating: all.tar                 
[chen@localhost test1]$ ls
all.tar  all.zip  a.txt  b.txt

5. 直接压缩目录

使用zip -r zip文件名 目录名,压缩整个目录:

shell 复制代码
[chen@localhost ~]$ ls
公共  模板  视频  图片  文档  下载  音乐  桌面  temp  test1  test2
[chen@localhost ~]$ zip -r test1.zip test1
  adding: test1/ (stored 0%)
  adding: test1/a.txt (stored 0%)
  adding: test1/b.txt (stored 0%)
[chen@localhost ~]$ ls
公共  模板  视频  图片  文档  下载  音乐  桌面  temp  test1  test1.zip  test2

6. 直接解压为目录

使用unzip zip文件名 -d 目录名,可以将压缩文件解压到指定目录。

shell 复制代码
[chen@localhost ~]$ unzip test1.zip -d  test1
Archive:  test1.zip
   creating: test1/test1/
 extracting: test1/test1/a.txt       
 extracting: test1/test1/b.txt       
[chen@localhost ~]$ ls
公共  模板  视频  图片  文档  下载  音乐  桌面  temp  test1  test1.zip  test2

需要注意的是,解压后,test1下面为之前所有内容,由于之前我们已经压缩了一个test1目录,所以test1下面还有个test1。

相关推荐
likfishdn2 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean22 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=24 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
吃汤圆的抹香鲸1 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
sz66cm2 小时前
Linux基础 -- ARM 32 位架构动态注入代码技术文档
linux·arm开发·架构
Mr.pyZhang4 小时前
Android构建系统 - 04 编译产物
android·linux