Linux :: 压缩与解压指令【1】:zip / unzip 指令:压缩与解压用法详解 您所在的位置:网站首页 解压不了7z压缩包 Linux :: 压缩与解压指令【1】:zip / unzip 指令:压缩与解压用法详解

Linux :: 压缩与解压指令【1】:zip / unzip 指令:压缩与解压用法详解

2023-06-12 00:51| 来源: 网络整理| 查看: 265

前言:本篇是 Linux 基本操作篇章的内容! 笔者使用的环境是基于腾讯云服务器:CentOS 7.6 64bit。

学习集:

C++ 入门到入土!!!学习合集Linux 从命令到网络再到内核!学习合集

目录索引: 1. 基本用法及功能 2. 基本用法:压缩/解压指定文件【注意代码示例内容!】 3. 「-r」:压缩指定目录 4. 「-d」:解压到指定目录 5. 相关文章或系列推荐

1. 基本用法及功能

基本用法:

压缩:zip 压缩文件.zip 目录或文件解压:unzip 目录或文件

注:注意.zip 后缀!

功能:将目录或文件压缩成zip格式

2. 基本用法:压缩/解压指定文件

注:若不含可选参数压缩目录,只会压缩一个空目录出来!!!

用法:zip 压缩后名.zip 压缩对象

/* 创建测试用例 */ [Mortal@VM-12-16-centos test_findsome]$ cd ~ [Mortal@VM-12-16-centos ~]$ mkdir test_zip [Mortal@VM-12-16-centos ~]$ cd test_zip [Mortal@VM-12-16-centos test_zip]$ mkdir -p a/aa/aa [Mortal@VM-12-16-centos test_zip]$ echo "helle" > t1.txt [Mortal@VM-12-16-centos test_zip]$ echo "test zip" > a/t2.txt [Mortal@VM-12-16-centos test_zip]$ echo "test zip a/aa/aaa" > a/aa/aa/t2.txt [Mortal@VM-12-16-centos test_zip]$ tree . . |-- a | |-- aa | | `-- aa | | `-- t2.txt | `-- t2.txt `-- t1.txt 3 directories, 3 files /* 压缩指定文件 */ [Mortal@VM-12-16-centos test_zip]$ zip t1_zip.zip t1.txt adding: t1.txt (stored 0%) [Mortal@VM-12-16-centos test_zip]$ ls a t1.txt t1_zip.zip(在命令行下是红色) /* 压缩指定目录:注:若不含可选参数压缩目录,只会压缩一个空目录出来!!! */ [Mortal@VM-12-16-centos test_zip]$ zip a_zip.zip a adding: a/ (stored 0%) [Mortal@VM-12-16-centos test_zip]$ ls a a_zip.zip t1.txt t1_zip.zip /* 解压指定文件 */ [Mortal@VM-12-16-centos test_zip]$ mkdir unzip_test [Mortal@VM-12-16-centos test_zip]$ cp t1_zip.zip unzip_test/ [Mortal@VM-12-16-centos test_zip]$ cd unzip_test/ [Mortal@VM-12-16-centos unzip_test]$ ls t1.txt t1_zip.zip [Mortal@VM-12-16-centos unzip_test]$ cat t1.txt helle /* 解压指定目录(不含指定可选项的压缩目录) */ [Mortal@VM-12-16-centos unzip_test]$ cp ../a_zip.zip . [Mortal@VM-12-16-centos unzip_test]$ ls a_zip.zip t1.txt t1_zip.zip [Mortal@VM-12-16-centos unzip_test]$ unzip a_zip.zip Archive: a_zip.zip creating: a/ [Mortal@VM-12-16-centos unzip_test]$ ls a a_zip.zip t1.txt t1_zip.zip [Mortal@VM-12-16-centos unzip_test]$ ll a total 0 /* 若不含可选参数压缩目录,只会解压一个空目录出来!!! */ 3. 「-r」:压缩/解压指定目录

-r:递归处理,将指定目录下的所有文件和子目录一并处理

[Mortal@VM-12-16-centos test_zip]$ zip -r a_zip.zip a adding: a/ (stored 0%) adding: a/t2.txt (stored 0%) adding: a/aa/ (stored 0%) adding: a/aa/aa/ (stored 0%) adding: a/aa/aa/t2.txt (deflated 6%) [Mortal@VM-12-16-centos test_zip]$ cd unzip_test/ [Mortal@VM-12-16-centos unzip_test]$ ls a a_zip.zip t1.txt t1_zip.zip [Mortal@VM-12-16-centos unzip_test]$ rm * rm: cannot remove ‘a’: Is a directory [Mortal@VM-12-16-centos unzip_test]$ ls a [Mortal@VM-12-16-centos unzip_test]$ cp ../a_zip.zip . [Mortal@VM-12-16-centos unzip_test]$ ls a a_zip.zip [Mortal@VM-12-16-centos unzip_test]$ rm -rf a [Mortal@VM-12-16-centos unzip_test]$ ls a_zip.zip [Mortal@VM-12-16-centos unzip_test]$ unzip a_zip.zip Archive: a_zip.zip creating: a/ extracting: a/t2.txt creating: a/aa/ creating: a/aa/aa/ inflating: a/aa/aa/t2.txt [Mortal@VM-12-16-centos unzip_test]$ ls a a_zip.zip [Mortal@VM-12-16-centos unzip_test]$ tree . . |-- a | |-- aa | | `-- aa | | `-- t2.txt | `-- t2.txt `-- a_zip.zip 3 directories, 3 files [Mortal@VM-12-16-centos unzip_test]$ cat a/aa/aa/t2.txt test zip a/aa/aaa 4. 「-d」:解压到指定目录

-d:作用:解压到指定目录【若目录不存在,则自动创建】

用法:unzip 解压对象 -d 指定目录

[Mortal@VM-12-16-centos unzip_test]$ ls a a_zip.zip [Mortal@VM-12-16-centos unzip_test]$ mkdir test_d [Mortal@VM-12-16-centos unzip_test]$ ls a a_zip.zip test_d [Mortal@VM-12-16-centos unzip_test]$ unzip a_zip.zip -d test_d/ Archive: a_zip.zip creating: test_d/a/ extracting: test_d/a/t2.txt creating: test_d/a/aa/ creating: test_d/a/aa/aa/ inflating: test_d/a/aa/aa/t2.txt [Mortal@VM-12-16-centos unzip_test]$ ls test_d/ a [Mortal@VM-12-16-centos unzip_test]$ tree test_d test_d `-- a |-- aa | `-- aa | `-- t2.txt `-- t2.txt 3 directories, 2 files 4. 相关文章或系列推荐

1. Linux 学习目录合集 ;



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有