Under Linux, zip, rar, tar, tar.gz , tar.bz2 , tar.xz , gzip, bzip2, XZ file archiving, compression and decompression

Philosophy of life 2020-11-10 10:44:14
linux zip rar tar tar.gz


One . About packaging and compression

1. pack ( Packaging is also known as archiving ) It refers to turning a large number of files or directories into a single file , Compression is to change a large file into a small file through a specific compression algorithm .

2. The benefits of archiving and compressing files : Easy to manage , Save hard disk resources , Speed up file transfer .

3.LINUX The common suffix name of archive compressed file in ( Archive compression format ):

Archive compression suffix Format description
.rar Said by WinRAR Files generated by the compression tool
.zip Said by zip Files generated by the compression tool
.gz Said by gzip Files generated by the compression tool
.bz2 Said by bzip2 Files generated by the compression tool
.xz Said by xz Files generated by the compression tool
.tar Said by tar The packer packages the generated files
.tar.gz First of all tar Tool packing , Then from gzip Tool to compress the generated file
.tar.bz2 First of all tar Tool packing , Then from bzip2 Tool to compress the generated file
.tar.xz First of all tar Tool packing , Then from xz Tool to compress the generated file

Two .linux Yes rar Compression and decompression of files

1.rar The format is windows The most common compression format of the system ,rar Compressed files can be made by WinRAR Compression generation ,RAR It's a patent document , Used for data compression and archiving

package ,RAR Usually it's more like ZIP High compression ratio , But compress / Decompression is slow . commonly linux It's all through tar Package files , Rarely deal with rar file , But inevitably there will be rar Format

The file of , We have to learn to deal with such documents .

2.linux Compression and decompression rar Files use rarlinux Program , This program needs to use the source code to compile and install ( Please check the installation details of source code compilation “linux Source code compilation and installation software principle ” Chapter

section ),rar The syntax of the compressed file is :rar a Compressed file name Files that need to be compressed / Catalog ,rar The syntax of decompressing the file is :rar x Compressed files .

#linux Compression and decompression rar Files use rarlinux Program
[root@node5 ~]# wget http://www.rarlab.com/rar/rarlinux-3.8.0.tar.gz
# Unzip the file
[root@node5 ~]# tar xf rarlinux-3.8.0.tar.gz
[root@node5 ~]# cd rar
# Compilation and installation rarlinux
[root@node5 ~]# make -j 4 && make install
#centos Compilation and installation rarlinux-3.8.0.tar.gz After the document , perform rar There may be “bash: /usr/local/bin/rar: /lib/ld-linux.so.2: bad ELF interpreter:No such file or directory” Such a report is wrong , You need to install the following two dependency packages
[root@node5 ~]# yum install glibc.i686
[root@node5 ~]# yum install libstdc++.so.6 -y
#rar The syntax of the compressed file is :rar a Compressed file name Files that need to be compressed / Catalog
[root@node5 ~]# rar a etc.rar /etc
[root@node5 ~]# ll etc.rar -h
-rw-r--r-- 1 root root 15M Nov 2 23:23 etc.rar
#rar The syntax of decompressing the file is :rar x Compressed files
[root@node5 ~]# rar x etc.rar
[root@node5 ~]# ll -d etc
drwxr-xr-x 101 root root 8192 Nov 2 23:17 etc
# see rar Command help , Direct input rar that will do
[root@node5 ~]# rar
RAR 3.80 Copyright (c) 1993-2008 Alexander Roshal 16 Sep 2008
Shareware version Type RAR -? for help
Usage: rar <command> -<switch 1> -<switch N> <archive> <files...>
<@listfiles...> <path_to_extract\>
<Commands>
a Add files to archive
c Add archive comment
cf Add files comment
ch Change archive parameters
cw Write archive comment to file

3、 ... and . Use tar File the documents , Compress , decompression

1.tar Command is used to package files , Compression and decompression .

2.tar The package of the command is to put several files / The directory is assembled in a file , adopt tar Packed files , have access to gzip,bzip2 or xz Wait for a compression tool to compress .

3.tar The grammar format of is :tar [OPTION...] [FILE]...,tar The common parameters of the command are :

  • ​ -c create create a file
  • ​ -x -extract [ˈekstrækt] extract Unzip the restore file
  • ​ -v --verbose Show the execution details
  • ​ -f --file Specify the backup file
  • ​ -t --list List which files are included in the package , No unpacking , Check the contents of the package
  • ​ -C ( Capitalization )--directory Specify the extraction location

3.1 tar Archive and decompress files

Archive only files, not compress

# Yes /boot directories
#tar You can leave the parameters of “-”,tar -cvf boot.tar /boot Equivalent to tar cvf boot.tar /boot
# This sentence appears when packing the file “tar: Removing leading `/' from member names”, This is because : When using absolute pathnames to archive files , The previous... In the path will be deleted from the file name by default / Symbol , When you decompress like this , It will be unzipped directly to the current directory . If you don't remove / Compress , When unpacking , Release files directly by absolute path , The file of this path in the original system will be overwritten .
[root@node5 ~]# tar -cvf boot.tar /boot
tar: Removing leading `/' from member names
/boot/
/boot/efi/
/boot/efi/EFI/
/boot/efi/EFI/centos/
/boot/grub2/
......
[root@node5 ~]# ll boot.tar -h
-rw-r--r-- 1 root root 92M Nov 3 10:57 boot.tar
# decompression
[root@node5 ~]# tar -xvf boot.tar
[root@node5 ~]# ll -d boot
dr-xr-xr-x 5 root root 4096 Apr 26 2019 boot
# Specify the extraction location -C
[root@node5 ~]# tar xf boot.tar -C /opt/
[root@node5 ~]# ll -d /opt/boot
dr-xr-xr-x 5 root root 4096 Apr 26 2019 /opt/boot
# Package the specified files and directories
[root@node5 ~]# tar cf guidan.tar 201810240430234009.pcm baidu.html iu.jpg wanyi.txt logqiege.sh stick
[root@node5 ~]# ll -h guidan.tar
-rw-r--r-- 1 root root 110K Nov 3 11:08 guidan.tar
# No decompression , see tar The contents of the bag
[root@node5 ~]# tar tf guidan.tar
201810240430234009.pcm
baidu.html
iu.jpg
wanyi.txt
logqiege.sh
stick/
[root@node5 ~]# tar cf boot.tar /boot
tar: Removing leading `/' from member names
[root@node5 ~]# ll -h boot.tar
-rw-r--r-- 1 root root 92M Nov 3 11:22 boot.tar
# Unzip the specified file ,boot There's... In the catalog initramfs-3.10.0-693.el7.x86_64.img file , Now we just want to unzip this file , Other files are not decompressed
[root@node5 ~]# tar xf boot.tar boot/initramfs-3.10.0-693.el7.x86_64.img
[root@node5 ~]# ll boot/initramfs-3.10.0-693.el7.x86_64.img -h
-rw------- 1 root root 20M Apr 26 2019 boot/initramfs-3.10.0-693.el7.x86_64.img

3.2 The addition and deletion of Archives

1. This step adds and removes the packaged files , And specific packaging .

[root@node5 opt]# ls
apache-tomcat-8.0.51 boot.tar boot.tar.bz2 boot.tar.gz boot.tar.xz nginx sdb6_fulldump sdb6_incredump1 sdb6_incredump2 xfsdump_sdb6 xfsdump_shadow
# Package the specified files and directories
[root@node5 opt]# tar cf ceshi.tar sdb6_fulldump sdb6_incredump1 sdb6_incredump2 xfsdump_sdb6
# No decompression , see tar The contents of the bag
[root@node5 opt]# tar tf ceshi.tar
sdb6_fulldump
sdb6_incredump1
sdb6_incredump2
xfsdump_sdb6
#-r: Append files to the end of a compressed archive
[root@node5 opt]# tar rf ceshi.tar xfsdump_shadow
[root@node5 opt]# tar tf ceshi.tar
sdb6_fulldump
sdb6_incredump1
sdb6_incredump2
xfsdump_sdb6
xfsdump_shadow
# Delete the specified file from the compressed archive
[root@node5 opt]# tar --delete -f ceshi.tar sdb6_fulldump
[root@node5 opt]# tar tf ceshi.tar
sdb6_incredump1
sdb6_incredump2
xfsdump_sdb6
xfsdump_shadow
# Yes /usr/local/nginx/conf Catalog for packaging , But exclude with default End and end with types Final document
[root@node5 opt]# tar cf nginx1.19.tar /usr/local/nginx/conf --exclude=/usr/local/nginx/conf/*.default --exclude=/usr/local/nginx/conf/*.types
tar: Removing leading `/' from member names
# see tar Package discovery , Not to default End and end with types Final document
[root@node5 opt]# tar tf nginx1.19.tar
usr/local/nginx/conf/
usr/local/nginx/conf/koi-win
usr/local/nginx/conf/koi-utf
usr/local/nginx/conf/win-utf
usr/local/nginx/conf/fastcgi_params
usr/local/nginx/conf/fastcgi.conf
usr/local/nginx/conf/uwsgi_params
usr/local/nginx/conf/scgi_params
usr/local/nginx/conf/nginx.conf

3.3 tar Archive, compress and decompress files

1. This step not only archives the files , And compress it accordingly .

2.tar To compress the common parameters :

  • ​ -z, --gzip With gzip Is compressed :tar zcvf newfile.tar.gz SOURCE , Extension : tar.gz
  • ​ -j : With bz2 Is compressed :tar jcvf newfile.tar.bz2 SOURCE Extension :tar.bz2
  • ​ -J : With xz Is compressed :tar Jcvf newfile.tar.xz SOURCE Extension :tar.xz

3. Yes /boot The directory is compressed and decompressed in three different ways , And compare the compression ratio .

[root@node5 ~]# cd /opt/
[root@node5 opt]# pwd
/opt
[root@node5 opt]# ls
apache-tomcat-8.0.51 nginx sdb6_fulldump sdb6_incredump1 sdb6_incredump2 xfsdump_sdb6 xfsdump_shadow
# establish tar package
[root@node5 opt]# tar cf boot.tar /boot
tar: Removing leading `/' from member names
# establish tar.gz package
[root@node5 opt]# tar zcf boot.tar.gz /boot
tar: Removing leading `/' from member names
# decompression tar.gz package
[root@node5 opt]# tar zxf boot.tar.gz
# establish tar.bz2 package
[root@node5 opt]# tar jcf boot.tar.bz2 /boot
tar: Removing leading `/' from member names
# decompression tar.bz2 package
[root@node5 opt]# tar jxf boot.tar.bz2
# decompression tar.bz2 Package to /home/elk/ Catalog
[root@node5 opt]# tar jxf boot.tar.bz2 -C /home/elk/
[root@node5 opt]# ll /home/elk/boot -dh
dr-xr-xr-x 5 root root 4.0K Apr 26 2019 /home/elk/boot
# establish tar.xz package
[root@node5 opt]# tar Jcf boot.tar.xz /boot
tar: Removing leading `/' from member names
# decompression tar.xz package
[root@node5 opt]# tar Jxf boot.tar.xz
# Compare three compressed files , Find out boot.tar.xz The compression ratio is the highest , But it takes the most time
[root@node5 opt]# ll -h boot.tar*
-rw-r--r-- 1 root root 92M Nov 3 14:51 boot.tar
-rw-r--r-- 1 root root 84M Nov 3 14:54 boot.tar.bz2
-rw-r--r-- 1 root root 84M Nov 3 14:52 boot.tar.gz
-rw-r--r-- 1 root root 82M Nov 3 15:15 boot.tar.xz

Four .linux Yes zip Compression and decompression of files

1.ZIP File format is a file format for data compression and document storage , Original name Deflate, The inventor was Phil · Katz (Phil Katz),zip Format of compressed file in linux and

windows It's very common , stay linux in ,zip It's a compressor ,unzip It's a decompressor .

[root@node5 opt]# pwd
/opt
# take /usr/local/nginx/conf/ All the conf The file is compressed into a zip package
[root@node5 opt]# zip conf.zip /usr/local/nginx/conf/*.conf
adding: usr/local/nginx/conf/fastcgi.conf (deflated 60%)
adding: usr/local/nginx/conf/nginx.conf (deflated 64%)
# Compressed files
[root@node5 opt]# zip shadow.zip /etc/shadow
adding: etc/shadow (deflated 43%)
# Compressed Directory
[root@node5 opt]# zip -r boot.zip /boot
# decompression zip package
[root@node5 opt]# unzip conf.zip
Archive: conf.zip
inflating: usr/local/nginx/conf/fastcgi.conf
inflating: usr/local/nginx/conf/nginx.conf
[root@node5 opt]# ls usr/local/nginx/conf/
fastcgi.conf nginx.conf
# decompression zip Package to the specified directory
[root@node5 opt]# unzip conf.zip -d /home/elk/
Archive: conf.zip
inflating: /home/elk/usr/local/nginx/conf/fastcgi.conf
inflating: /home/elk/usr/local/nginx/conf/nginx.conf
[root@node5 opt]# ls /home/elk/usr/local/nginx/conf/
fastcgi.conf nginx.conf

5、 ... and . Use gzip,bzip2,xz Compressed files , Unzip the file , see file

[root@node5 opt]# ls
apache-tomcat-8.0.51 nginx sdb6_fulldump sdb6_incredump1 sdb6_incredump2 usr xfsdump_sdb6 xfsdump_shadow
#gzip Compress
[root@node5 opt]# gzip xfsdump_shadow
[root@node5 opt]# ls
apache-tomcat-8.0.51 nginx sdb6_fulldump sdb6_incredump1 sdb6_incredump2 usr xfsdump_sdb6 xfsdump_shadow.gz
# see gzip Compressed file
[root@node5 opt]# zcat xfsdump_shadow.gz
# decompression gzip file
[root@node5 opt]# gzip -d xfsdump_shadow.gz
#bzip2 Compress
[root@node5 opt]# bzip2 xfsdump_sdb6
[root@node5 opt]# ls
apache-tomcat-8.0.51 nginx sdb6_fulldump sdb6_incredump1 sdb6_incredump2 usr xfsdump_sdb6.bz2 xfsdump_shadow.gz
# see bzip2 Compressed file
[root@node5 opt]# bzcat xfsdump_sdb6.bz2
# decompression bzip2 file
[root@node5 opt]# bzip2 -d xfsdump_sdb6.bz2
#xz Compress
[root@node5 opt]# xz sdb6_incredump2
[root@node5 opt]# ls
apache-tomcat-8.0.51 nginx sdb6_fulldump sdb6_incredump1 sdb6_incredump2.xz usr xfsdump_sdb6.bz2 xfsdump_shadow.gz
# see xz Compressed file
[root@node5 opt]# xzcat sdb6_incredump2.xz
# decompression xz file
[root@node5 opt]# xz -d sdb6_incredump2.xz
版权声明
本文为[Philosophy of life]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云