位置: 编程技术 - 正文

Linux中文件的压缩与解压缩命令操作示例集锦(linux系统文件压缩命令)

编辑:rootadmin

推荐整理分享Linux中文件的压缩与解压缩命令操作示例集锦(linux系统文件压缩命令),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:linux的压缩文件命令,linux中压缩文件夹,linux中压缩文件的命令,linux对文件进行压缩的命令,linux中文件压缩,linux压缩文件,linux对文件进行压缩的命令,linux系统文件压缩命令,内容如对您有帮助,希望把文章链接给更多的朋友!

所谓压缩就是将原有的文件通过不同的编码技术进行运算,以减少数据存储所需要的空间,使用前再利用解压缩还原源文件的内容即可。和windows一样,在linux下也存在多种压缩与解压缩方法。

1、zip压缩与解压缩 zip是最为广泛使用的压缩程序,经它压缩的文件会产生扩展名为zip的压缩文件,而且这种格式在多种系统上可以使用,像windows中的winzip 下面看一下在linux中如何建立zip文件。 我们在终端中输入zip会出现这个命令的一些介绍和参数的意义。复制代码代码如下:xiaopeng@ubuntu:~/test$ zipCopyright (c) - Info-ZIP - Type 'zip "-L"' for software license.Zip 2. (June th ). Usage:zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list] The default action is to add or replace zipfile entries from list, which can include the special name - to compress standard input. If zipfile and list are omitted, zip compresses stdin to stdout. -f freshen: only changed files -u update: only changed or new files -d delete entries in zipfile -m move into zipfile (delete files) -r recurse into directories -j junk (don't record) directory names -0 store only -l convert LF to CR LF (-ll CR LF to LF) -1 compress faster -9 compress better -q quiet operation -v verbose operation/print version info -c add one-line comments -z add zipfile comment -@ read names from stdin -o make zipfile as old as latest entry -x exclude the following names -i include only the following names -F fix zipfile (-FF try harder) -D do not add directory entries -A adjust self-extracting exe -J junk zipfile prefix (unzipsfx) -T test zipfile integrity -X eXclude eXtra file attributes -y store symbolic links as the link instead of the referenced file -R PKZIP recursion (see manual) -e encrypt -n don't compress these suffixes 下面我们就最简单的实验一下。我们就是把当前目录下文件名以test开头的所有文件压缩文一个文件,并可以查看一下压缩比。(红色是我的注释)复制代码代码如下:xiaopeng@ubuntu:~/test$ ls -lh总用量 K复制代码代码如下:-rw-r--r-- 1 xiaopeng xiaopeng -- : test1-rw-r--r-- 1 xiaopeng xiaopeng 1.3K -- : test2-rw-r--r-- 1 xiaopeng xiaopeng 3.4K -- : test3-rw-r--r-- 1 xiaopeng xiaopeng 9.9K -- : test4复制代码代码如下:xiaopeng@ubuntu:~/test$ zip test.zip test* zip命令后面先跟压缩后的文件名,这里是test.zip,当然后缀名不是必须的。然后跟要压缩的文件名。这里用的test*指的是全部以test开头的文件,包括test1 test2 test3 test4 adding: test1 (deflated %) 这里显示的是压缩比 adding: test2 (deflated %) adding: test3 (deflated %) adding: test4 (deflated %) 大体可以看出源文件越大,压缩比就越大复制代码代码如下:xiaopeng@ubuntu:~/test$ ls -lh总用量 K复制代码代码如下:-rw-r--r-- 1 xiaopeng xiaopeng -- : test1-rw-r--r-- 1 xiaopeng xiaopeng 1.3K -- : test2-rw-r--r-- 1 xiaopeng xiaopeng 3.4K -- : test3-rw-r--r-- 1 xiaopeng xiaopeng 9.9K -- : test4-rw-r--r-- 1 xiaopeng xiaopeng 5.0K -- : test.zipxiaopeng@ubuntu:~/test$ 上面是压缩了相同类型的文件,其实也可以把不同类型的文件压缩到一起。有时候为了节省硬盘空间,可以在建立压缩文件后,自动删除原始文件,此时只要带一个 -m 的参数就可以。复制代码代码如下: xiaopeng@ubuntu:~/test$ ls -lh总用量 K复制代码代码如下:-rw-r--r-- 1 xiaopeng xiaopeng -- : test1-rw-r--r-- 1 xiaopeng xiaopeng 1.3K -- : test2-rw-r--r-- 1 xiaopeng xiaopeng 3.4K -- : test3-rw-r--r-- 1 xiaopeng xiaopeng 9.9K -- : test4xiaopeng@ubuntu:~/test$ zip -m test.zip test* 带参数-mupdating: test1 (deflated %)updating: test2 (deflated %)updating: test3 (deflated %)updating: test4 (deflated %)xiaopeng@ubuntu:~/test$ ls -lh总用量 8.0K复制代码代码如下:-rw-r--r-- 1 xiaopeng xiaopeng 5.0K -- : test.zipxiaopeng@ubuntu:~/test$ 可以看出 原始文件已经被删除,只有压缩文件留下了。 在压缩一些目录的时候,经出在目录中会有子目录,此时根据子目录中的文件是否压缩分为两种情况,一种是压缩,一种是忽略自录中的内容,如果选择压缩子目录,则使用-r参数,如果不压缩,则使用-j 参数下面举例,一个是-r 一个是-j复制代码代码如下:xiaopeng@ubuntu:~/test$ ls -lh总用量 K复制代码代码如下:drwxr-xr-x 2 xiaopeng xiaopeng 4.0K -- : pdf-rw-r--r-- 1 xiaopeng xiaopeng -- : test1-rw-r--r-- 1 xiaopeng xiaopeng 1.3K -- : test2-rw-r--r-- 1 xiaopeng xiaopeng 3.4K -- : test3-rw-r--r-- 1 xiaopeng xiaopeng 9.9K -- : test4xiaopeng@ubuntu:~/test$ zip -r test.zip * 压缩当前目录所有内容,r 参数说明pdf这个子目录中的内容也压缩 adding: pdf/ (stored 0%) adding: pdf/case_Contact.pdf (deflated %) adding: pdf/case_KRUU.pdf (deflated 9%) adding: pdf/case_howard_county_library.pdf (deflated %) adding: test1 (deflated %) adding: test2 (deflated %) adding: test3 (deflated %) adding: test4 (deflated %) xiaopeng@ubuntu:~/test$ 下面的情况是子目录不压缩复制代码代码如下: xiaopeng@ubuntu:~/test$ ls -l 总用量 复制代码代码如下: drwxr-xr-x 2 xiaopeng xiaopeng -- : pdf-rw-r--r-- 1 xiaopeng xiaopeng -- : test1-rw-r--r-- 1 xiaopeng xiaopeng -- : test2-rw-r--r-- 1 xiaopeng xiaopeng -- : test3-rw-r--r-- 1 xiaopeng xiaopeng -- : test4xiaopeng@ubuntu:~/test$ zip -j test.zip * adding: test1 (deflated %) adding: test2 (deflated %) adding: test3 (deflated %) adding: test4 (deflated %) 子目录pdf被忽略复制代码代码如下:xiaopeng@ubuntu:~/test$令外一个技巧: 某些文件因为编码的原因,已经大幅的减少了文件的大小,如GIF,JPG 等格式,在用zip压缩几乎没什么作用而浪费了时间,此时可一用-n参数直接保存这些文件而不压缩。例如:复制代码代码如下:xiaopeng@ubuntu:~/test$ ls -lh总用量 K复制代码代码如下:-rw-r--r-- 1 xiaopeng xiaopeng K -- : duality.jpg-rw-r--r-- 1 xiaopeng xiaopeng -- : test1-rw-r--r-- 1 xiaopeng xiaopeng 1.3K -- : test2-rw-r--r-- 1 xiaopeng xiaopeng 3.4K -- : test3-rw-r--r-- 1 xiaopeng xiaopeng 9.9K -- : test4-rw-r--r-- 1 xiaopeng xiaopeng K -- : test.jpgxiaopeng@ubuntu:~/test$ zip -n .jpg test.zip * adding: duality.jpg (stored 0%) adding: test1 (deflated %) adding: test2 (deflated %) adding: test3 (deflated %) adding: test4 (deflated %) adding: test.jpg (stored 0%) jpg格式的没有压缩而是直接保存了复制代码代码如下:xiaopeng@ubuntu:~/test$如果需要直接保存的格式多于一个,可以用冒号隔开 如: -n .jpg: .mpg

小技巧,有时候一个目录下要压缩的文件很多,但是有那么很少的几个不压缩,那么我们可以用-x参数来排除这几个不压缩的。例如复制代码代码如下:xiaopeng@ubuntu:~/test$ lsduality.jpg test1 test2 test3 test4 test.jpg test.zipxiaopeng@ubuntu:~/test$ zip -n .jpg test.zip * -x test2 不压缩test2updating: duality.jpg (stored 0%)updating: test1 (deflated %)updating: test3 (deflated %)updating: test4 (deflated %)updating: test.jpg (stored 0%)xiaopeng@ubuntu:~/test$可以看到test2没有被压缩,而是直接跳过了它。

压缩链接,zip会先读取该链接的指向的原文件的内容,然后再压缩,而且压缩完了,该链接也就不存在了。

Linux中文件的压缩与解压缩命令操作示例集锦(linux系统文件压缩命令)

另外,压缩率也是可以调整的。等级是1到9,1最低,9最高,默认是6 。我们可以用1和9来比较下,压缩率。复制代码代码如下:xiaopeng@ubuntu:~/test$ zip -1 low.zip * adding: test1 (deflated %) adding: test2 (deflated %) adding: test3 (deflated %) adding: test4 (deflated %)xiaopeng@ubuntu:~/test$ zip -9 high.zip * adding: low.zip (deflated 4%) adding: test1 (deflated %) adding: test2 (deflated %) adding: test3 (deflated %) adding: test4 (deflated %) 因为文件都比较小,效果不是很明显,但是9的压缩率确实高了一点点。 压缩率高,节省空间,但是压缩时间要长,压缩率低,节省空间少,但是用时间少,所以我们要合理选择压缩率,一般都用默认。

zip文件解压缩。这个比较简单,就是unzip命令。复制代码代码如下:xiaopeng@ubuntu:~/test$ lstest.zipxiaopeng@ubuntu:~/test$ unzip test.zipArchive: test.zip inflating: test1 inflating: test2 inflating: test3 inflating: test4 xiaopeng@ubuntu:~/test$ 当然也可以用-x参数来指定哪个文件不需要压缩。复制代码代码如下:xiaopeng@ubuntu:~/test$ unzip test.zip -x test3 test3不需要压缩出来Archive: test.zip inflating: test1 inflating: test2 inflating: test4 xiaopeng@ubuntu:~/test$ 还有一个很有用的参数,-Z ,注意是大写的Z 。作用是查看压缩文件的内容。就像windows中的winzip,我们不用解压缩,也可以打开看看里面有什么文件,文件的类型什么。比如我想看看test.zip里面的内容,而又不想把这个解压缩了再看,可以如下操作。复制代码代码如下:xiaopeng@ubuntu:~/test$ unzip -Z test.zipArchive: test.zip bytes 4 files-rw-r--r-- 2.3 unx tx defN -Jun- : test1-rw-r--r-- 2.3 unx tx defN -Jun- : test2-rw-r--r-- 2.3 unx tx defN -Jun- : test3-rw-r--r-- 2.3 unx tx defN -Jun- : test files, bytes uncompressed, bytes compressed: .4%xiaopeng@ubuntu:~/test$ 当然除了这些参数外,还有很多参数可以使用,这里就不一一实验了,我们可以在使用的过程中加以掌握。

2、zip与 tar 如果你在Linux里面安装过软件压缩包,对这个以.tar.gz为后缀的压缩文件不会陌生,比如我们在Linux QQ 的下载页面 ,就会看到其中一个安装包就是.tar.gz包。 这种包带两个后缀是有原因的,gz和tar 是分别由两种程序产生的。gz时由gzip压缩而成的压缩文件,压缩效果和zip差不多,但是和zip最大的不同在于,gzip无法把很多个单一文件压缩成一个单一文件,所以tar就有了用武之地,tar不是什么压缩程序,它是用来打包文件的。tar和gzip一见如故,两个人合作起来实现压缩,也就是当多个文件压缩时,先用tar把这些文件打包,成为.tar的包,然后再由gzip压缩这个包,于是就有了.tar.gz的文件格式。 首先先看一下gzip和 gunzip的应用。gzip的用法很简单,后面加上要压缩的文件名就行。复制代码代码如下:xiaopeng@ubuntu:~/test$ ls -lh总用量 K复制代码代码如下:-rw-r--r-- 1 xiaopeng xiaopeng -- : test1-rw-r--r-- 1 xiaopeng xiaopeng 1.3K -- : test2-rw-r--r-- 1 xiaopeng xiaopeng 3.4K -- : test3-rw-r--r-- 1 xiaopeng xiaopeng 9.9K -- : test4xiaopeng@ubuntu:~/test$ gzip test1xiaopeng@ubuntu:~/test$ ls -lh总用量 K复制代码代码如下:-rw-r--r-- 1 xiaopeng xiaopeng -- : test1.gz-rw-r--r-- 1 xiaopeng xiaopeng 1.3K -- : test2-rw-r--r-- 1 xiaopeng xiaopeng 3.4K -- : test3-rw-r--r-- 1 xiaopeng xiaopeng 9.9K -- : test4 注意和zip的不同,只要在命令后加上要压缩的文件名即可,系统会自动为生成的压缩文件起名为原文件名加后缀.gz ,而且原文件在压缩完成后会被删除。 解压缩用gunzip复制代码代码如下:xiaopeng@ubuntu:~/test$ gunzip *.gzxiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4xiaopeng@ubuntu:~/test$ 完成后以前的压缩文件test1.gz也会被删除。 同样gzip在解压前也可以查看文件内容,用参数-l, gzip也支持压缩率修改,为1到9,和zip相同。

下面看tar的用应。tar是用来打包文件的,打包后的包的大小和以前所有原文件大小的和是相等的,(其实大小是不相等的,打完包后的大小大于源文件的大小和,这个可以验证一下。《Ubuntu 入门到精通》说一样大,显然是不对的)也就是说tar没有压缩的效果。tar有非常多的参数,可以通过在线帮助文档查看,或者用--help命令查看。这里我们只用简单用到几个。 首先是多个文件打包。看例子。复制代码代码如下:xiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4xiaopeng@ubuntu:~/test$ tar -cvf test.tar * 是把当前目录下的所有文件打包成test.tar 几个参数的意义为: c(Creat)建立新文件 v(Verbose)显示命令执行时的信息 f(File)指定打包为文件形式。复制代码代码如下:test1test2test3test4复制代码代码如下:xiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4 test.tarxiaopeng@ubuntu:~/test$ 要解开tar文件,只需把参数中的c改为x(eXtract)即可复制代码代码如下:xiaopeng@ubuntu:~/test$ ls test.tarxiaopeng@ubuntu:~/test$ tar -xvf test.tartest1test2test3test4xiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4 test.tarxiaopeng@ubuntu:~/test$

下面我们看一下tar和gzip合作完成对4个文件的压缩。步骤是先用tar打包,然后对这个.tar包用gzip压缩,最后得到.tar.gz文件。例子:复制代码代码如下:xiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4xiaopeng@ubuntu:~/test$ tar cvf test.tar * 首先打包成test.tartest1test2test3test4xiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4 test.tarxiaopeng@ubuntu:~/test$ gzip test.tar 把test.tar用gzip压缩成test.tar.gz 压缩包。xiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4 test.tar.gzxiaopeng@ubuntu:~/test$ 解压.tar.gz包时,和压缩过程相反,现解压,再tar把包打开。复制代码代码如下:xiaopeng@ubuntu:~/test$ lstest.tar.gzxiaopeng@ubuntu:~/test$ gunzip test.tar.gz 先用gunzip把.tar.gz包解压缩xiaopeng@ubuntu:~/test$ lstest.tarxiaopeng@ubuntu:~/test$ tar xvf test.tar 然后用tar把.tar包打开test1test2test3test4xiaopeng@ubuntu:~/test$ lstest1 test2 test3 test4 test.tarxiaopeng@ubuntu:~/test$ 还可以tar 和gzip同时实现的,只要在tar参数加一个z即可 tar -xvfz test.tar.gz 即可实现上面两个命令的功能。

还是比较好理解的。

在Linux系统上开启Initrd文件系统的方法 initialRAMdiskLinux初始RAM磁盘(initrd)是在系统引导过程中挂载的一个临时根文件系统,用来支持两阶段的引导过程。initrd文件中包含了各种可执行程序和

Linux系统中使用iostat命令检测磁盘的IO性能 iostat命令可以提供丰富的IO性能状态数据。iostat可以收集和显示系统输入/输出存储设备方面的统计信息.经常用于追查存储设备性能方面的问题,包括设备

详解Linux中获取全球唯一标示符UUID的方法 UUID(UniversallyUniqueIDentifiers),全球唯一标示符.它是一个标识系统中的存储设备的字符串,使其确定系统中的所有存储设备。为什么要使用UUID?因为系统自动

标签: linux系统文件压缩命令

本文链接地址:https://www.jiuchutong.com/biancheng/358916.html 转载请保留说明!

上一篇:腾讯云Linux系统怎么挂载磁盘?(腾讯linux服务器)

下一篇:在Linux系统上开启Initrd文件系统的方法(打开linux系统)

  • 税款所属期
  • 租厂房土地使用税
  • 只报税不做账有什么后果?
  • 支付所得税的会计处理
  • 消费税征税范围是什么口诀
  • 印花税的申报依据是什么
  • 政府补助是属于什么财务活动
  • 企业出包工程预付的工程款
  • 建筑企业一般纳税人简易计税办法
  • 高新技术企业季报填报
  • 应收退货成本会计科目代码
  • 期末账项调整的类型
  • 存在问题的具体表现和产生问题的原因分析
  • 长期股权投资收益会计处理
  • 现房销售土增税怎么缴纳
  • 会计上的未达账项是什么
  • 从支付宝里可以查出结婚个人信息吗
  • 不需要缴纳企业所得税的企业类型
  • 上个月有留抵税这个月怎么结转税金
  • 发票的审核之真假发票的查验
  • 第二个季度
  • 小微企业不超过300万所得税
  • 危险废物处理原则
  • 现金返利怎么做账
  • 收银员现金管理流程
  • 维修材料属于什么会计科目
  • win10wifi老是自动断开怎么回事
  • win11多开
  • 微软笔记本
  • PHP:mb_http_input()的用法_mbstring函数
  • 融资租入固定资产的账务处理
  • 实际收到的货款怎么做账
  • 旧货回收增值税率是多少
  • yolov教程
  • 吸收合并重组
  • 代码怎么用?
  • php获取指定日期的时间戳
  • 如何修改php.ini
  • 小规模纳税人减半征收的六税两费
  • 什么是分红型保险?
  • 餐饮定额发票能报销吗怎么报销
  • 企业从应付职工工资中代扣的职工房租应借记
  • php的输出语句主要有哪些
  • 个人所得税经营所得
  • 漏税处罚
  • mongodb morphia
  • sql server数据表
  • sqlserver如何使用
  • 注册资本在十年后怎么办
  • 行政事业单位赞助支出会计核算办法
  • 公司基本户里的钱有利息吗
  • 机关事业单位购买口罩
  • 专项资金补助经费如何入账
  • 固定资产折旧方法一经确定不得随意变更
  • 行政单位负债类科目包括
  • 补记式余额调节法怎么写项目
  • 买水果送礼
  • 企业内在
  • sql语句行转列
  • u盘装系统win8
  • win7系统管理在哪里
  • XP系统怎么设置屏幕常亮
  • 修改注册表优化Win10
  • rundll32找不到文件
  • linux确认命令
  • Win10系统安装步骤
  • 在linux操作系统中
  • win10怎么把动图设置成壁纸
  • unity对象池优缺点
  • JQuery.Ajax()的data参数类型实例详解
  • nodejs抓取网页内容
  • Android游戏开发书籍
  • 安卓 图形api
  • 协程有什么用
  • vue cli3 webpack配置
  • unity3d操作
  • python 入门
  • html做一个新闻app首页
  • 发票代码和发票号码有什么区别
  • 武汉代账公司一般怎么收费
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设