Linux基础学习之文件压缩工具-gzip
先看介绍文件 :/$ man gzip

GZIP(1)                                     General Commands Manual                                    GZIP(1)NAMEgzip, gunzip, zcat - compress or expand filesSYNOPSISgzip [ -acdfhklLnNrtvV19 ] [-S suffix] [ name ...  ]gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ...  ]zcat [ -fhLV ] [ name ...  ]DESCRIPTIONGzip  reduces the size of the named files using Lempel-Ziv coding (LZ77).  Whenever possible, each fileis replaced by one with the extension .gz, while keeping the same ownership modes, access and modifica‐tion  times.   (The default extension is z for MSDOS, OS/2 FAT, Windows NT FAT and Atari.)  If no filesare specified, or if a file name is "-", the standard input is compressed to the standard output.  Gzipwill only attempt to compress regular files.  In particular, it will ignore symbolic links.If the compressed file name is too long for its file system, gzip truncates it.  Gzip attempts to trun‐cate only the parts of the file name longer than 3 characters.  (A part is delimited by dots.)  If  thename consists of small parts only, the longest parts are truncated. For example, if file names are lim‐ited to 14 characters, gzip.msdos.exe is compressed to gzi.msd.exe.gz.  Names are not truncated on sys‐tems which do not have a limit on file name length.By default, gzip keeps the original file name and timestamp in the compressed file. These are used whendecompressing the file with the -N option. This is useful when the compressed file name  was  truncatedor when the timestamp was not preserved after a file transfer.Compressed files can be restored to their original form using gzip -d or gunzip or zcat.  If the origi‐nal name saved in the compressed file is not suitable for its file system, a new  name  is  constructedfrom the original one to make it legal.
#查看桌面上的文件以及文件夹,其中通过cp 1.txt 2.txt复制得到两个大小内容一致的文件
[wolf@localhost Desktop]$ ls
1  1.txt  2.txt
[wolf@localhost Desktop]$ ls -R
.:
1  1.txt  2.txt./1:
1.txt  2.txt
[wolf@localhost Desktop]$ ll
total 8
drwxrwxr-x. 2 wolf wolf   32 Nov  3 19:12 1
-rw-rw-r--. 1 wolf wolf 1828 Nov  3 19:09 1.txt
-rw-rw-r--. 1 wolf wolf 1828 Nov  3 19:10 2.txt

首先压缩文件1.txt

[wolf@localhost Desktop]$ gzip 1.txt
[wolf@localhost Desktop]$ ll
total 8
drwxrwxr-x. 2 wolf wolf   32 Nov  3 19:12 1
-rw-rw-r--. 1 wolf wolf   93 Nov  3 19:09 1.txt.gz
-rw-rw-r--. 1 wolf wolf 1828 Nov  3 19:10 2.txt

发现1.txt原始文件找不到了,生成了压缩文件1.txt.gz,大小又1828字节变为93字节,我们查看可以保留原始文件的压缩方法。

wolf@localhost Desktop]$ gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).Mandatory arguments to long options are mandatory for short options too.-c, --stdout      write on standard output, keep original files unchanged-d, --decompress  decompress-f, --force       force overwrite of output file and compress links-h, --help        give this help-k, --keep        keep (don't delete) input files-l, --list        list compressed file contents-L, --license     display software license-n, --no-name     do not save or restore the original name and timestamp-N, --name        save or restore the original name and timestamp-q, --quiet       suppress all warnings-r, --recursive   operate recursively on directories--rsyncable   make rsync-friendly archive-S, --suffix=SUF  use suffix SUF on compressed files--synchronous synchronous output (safer if system crashes, but slower)-t, --test        test compressed file integrity-v, --verbose     verbose mode-V, --version     display version number-1, --fast        compress faster-9, --best        compress betterWith no FILE, or when FILE is -, read standard input.Report bugs to <bug-gzip@gnu.org>.

可以看到-k参数可以保留原始文件

[wolf@localhost Desktop]$ ls
1  1.txt.gz  2.txt
[wolf@localhost Desktop]$ gzip -k 2.txt
[wolf@localhost Desktop]$ ls
1  1.txt.gz  2.txt  2.txt.gz

解压文件 -d选项

[wolf@localhost Desktop]$ ls
1  1.txt.gz  2.txt
[wolf@localhost Desktop]$ gzip -k 2.txt
[wolf@localhost Desktop]$ ls
1  1.txt.gz  2.txt  2.txt.gz
[wolf@localhost Desktop]$ gzip -d 1.txt.gz
[wolf@localhost Desktop]$ ls
1  1.txt  2.txt  2.txt.gz
[wolf@localhost Desktop]$ gzip -d 2.txt.gz
gzip: 2.txt already exists; do you wish to overwrite (y or n)? nnot overwritten
[wolf@localhost Desktop]$ ls
1  1.txt  2.txt  2.txt.gz
[wolf@localhost Desktop]$ gzip -d 2.txt.gz
gzip: 2.txt already exists; do you wish to overwrite (y or n)? y
[wolf@localhost Desktop]$ ls
1  1.txt  2.txt

最后,我们看一下,能不能讲文件夹进行一个压缩

[wolf@localhost Desktop]$ ls -R
.:
1  1.txt  2.txt./1:
1.txt  2.txt
[wolf@localhost Desktop]$ gzip -k 1.txt 2.txt
[wolf@localhost Desktop]$ ls
1  1.txt  1.txt.gz  2.txt  2.txt.gz
[wolf@localhost Desktop]$ ll
total 16
drwxrwxr-x. 2 wolf wolf   32 Nov  3 19:12 1
-rw-rw-r--. 1 wolf wolf 1828 Nov  3 19:09 1.txt
-rw-rw-r--. 1 wolf wolf   93 Nov  3 19:09 1.txt.gz
-rw-rw-r--. 1 wolf wolf 1828 Nov  3 19:10 2.txt
-rw-rw-r--. 1 wolf wolf   93 Nov  3 19:10 2.txt.gz

结果显示,这个是目录文件,直接给忽略,可以看出来不行。同样对两个文件进行压缩的话,也是生成两个压缩文件。
最后在解释文档里有讲到,压缩文件的时间戳与原始文件是一样的,保持不变,通过ll命令可以看到。
下一节进行归档tar命令的介绍。

Linux学习之文档压缩工具(gzip)相关推荐

  1. linux 文档操作,Linux学习之文档操作

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? The Linux Command Line 学习翻译 mkdir The mkdir command is used ...

  2. Linux 编辑doc,Linux命令大全(文档编辑).doc

    Linux命令大全(文档编辑) 文档编辑文档编辑-col 功能说明:过滤控制字符. 语 法:col [-bfx][-l] 补充说明:在许多UNIX说明文件里,都有RLF控制字符.当我们运用shell特 ...

  3. 深度学习在文档矫正中的应用

    深度学习在文档矫正中的应用 一.扫描文稿 在日常生活中,我们经常会使用到扫描文稿的功能.包括IOS备忘录自带的扫描功能.扫描全能王等,文稿扫描给我们带来了许多便利.文稿扫描可以应对的范围非常广.包括身 ...

  4. Linux 编辑doc,Linux 指令篇-文档编辑.doc

    Linux 指令篇-文档编辑 Linux 指令篇:文档编辑--col Intel嵌入式设计开发者秘笈(精品)[上海央邦]学一送一,超值!定向委培RHCA,通过考试年薪10W 安博亚威]CCIE考试通过 ...

  5. WPS for linux移动云文档

    我一度以为WPS for linux无法移动云文档 直到看到这篇文章:https://jingyan.baidu.com/article/f3e34a12195113f5ea653545.html 点 ...

  6. (六)MkDocs学习——部署文档

    mkdocs学习笔记系列 (一)MkDocs 学习--快速开始 (二)MkDocs学习笔记--撰写文档 (三)MkDocs学习--配置主题 (四)MkDocs学习--自定义主题 (五)MkDocs学习 ...

  7. at91sam9260ek开发板linux移植文档,AT91SAM9260EK开发板 Linux 移植 移植 文档

    AT91SAM9260EK开发板 Linux 移植 移植 文档 AT91SAM9260EKAT91SAM9260EKAT91SAM9260EKAT91SAM9260EK 开发板开发板开发板开发板 Li ...

  8. 各种学习资源 文档、手册 (Docker 、springboot 、Guava、git、logback 、Linux 、MQ、vue、Axios)

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. Docker 中文手册 :https://yeasy.gitbooks.io/docker_p ...

  9. Linux入门参考文档(超详细)

    一.Linux简介与安装 1.1 计算机的相关概念 1. 什么是计算机 能够接收使用者输入的指令与数据,经由中央处理器的算术与逻辑单元运算处理后,以产生或存储有用的新数据.比如计算器,手机,汽车导航系 ...

最新文章

  1. edittext 监听无效_Android中EditText 设置 imeOptions 无效问题的解决方法
  2. linux selinux 安全子系统简介
  3. python 绘制柱状图-Python使用Plotly绘图工具,绘制柱状图
  4. HoughLinesP函数(概率检测直线)
  5. No Architectures to Compile for (ONLY_ACTIVE_ARCH=
  6. 二叉堆详解实现优先级队列
  7. Google和百度都无法替代的10大深网搜索引擎
  8. 苹果又遭集体诉讼,网友拍手:干得漂亮......
  9. java stream groupingBy(classifier, downstream, mapFactory)
  10. Domino学习笔记之邮件发送程序
  11. php中until的用法,JavaScript_jQuery中nextUntil()方法用法实例,本文实例讲述了jQuery中nextUntil( - phpStudy...
  12. Windows右键菜单管理 图片右键菜单太长
  13. lighttpd和php关系,Lighttpd是什么
  14. android中APK开机自动运行
  15. flask项目中出现Error: While importing ‘manager‘, an ImportError was raised.
  16. 微信每日早安推送,自定义推送名称,企业号推送非订阅号测试号,python源码,无需第三方多个网站注册、无第三方接口,无基础快速上不了手
  17. 用Meta标签代码让360双核浏览器默认极速模式
  18. mysql查询平均工资最低的部门_查询出部门名称、部门的员工数、部门的平均工资、部门的最低收入雇员姓名和最高收入雇员的姓名...
  19. read和fread有什么区别
  20. 无线网卡驱动突然坏了怎么办

热门文章

  1. 湖北师范大学计信2018届操作系统实训(参考答案)
  2. 8255和8253的综合应用
  3. Linux网络编程之阻塞与非阻塞
  4. EXCEL 加减乘除
  5. 如何一键删除twitter
  6. 倍加福SJ10-E2传感器
  7. 日志系统优化选型之采集端
  8. telnet 命令行 android,telnet登录android手机,可以执行部分linux命令
  9. 百度语音识别——在线识别
  10. 代理商订货管理系统1.2版(分销模式+积分模式)正式上线