Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ File compression and packaging commands under Linux     - Linux operating system log system (Linux)

- Learning how to teach safety system to prevent your own IP leakage (Linux)

- Ubuntu System Log Configuration / var / log / messages (Linux)

- The basic method RHEL6 (CentOS6) used in the source package compiled RPM: Upgrade OpenSSH articles (Linux)

- Linux operating system, the internal and external security overview (Linux)

- In the case of using cgroups Ubuntu 14.04 and Docker (Linux)

- Nginx DHCP TFTP Kickstart set up automatic installation system (Server)

- Understand the security restore accidentally deleted critical system files (Linux)

- Git uses a small mind (Linux)

- Port Telnet command to detect the remote host is turned on (Linux)

- Spring loaded container finishes executing a method (Programming)

- Linux iptables: combat scenes (Linux)

- Windows environment Android Studio v1.0 Installation Guide (Linux)

- 8 Docker knowledge you may not know (Server)

- How VirtualBox and VMware virtual machine conversion (Linux)

- Docker Basic and Advanced (Linux)

- Oracle Automatic Diagnostic Repository (Automatic Diagnostic Repository, ADR) (Database)

- Ubuntu 14.04 LTS installed Hadoop 1.2.1 (distributed cluster mode) (Server)

- Ubuntu 15.04 installation Powercommands 2.0 (Linux)

- Open container cluster management system architecture and components introduced Kubernetes (Server)

 
         
  File compression and packaging commands under Linux
     
  Add Date : 2018-11-21      
         
         
         
  We must first understand two concepts: packing and compression.
Packaging refers to a lot of files or directories into a general file;
File compression sucked by a large number of compression algorithms into a small file.
Why do you want to distinguish between these two concepts? This stems from the many Linux compression program only for a compressed file, so that when you want to compress a lot of files, you must first be a huge pile of documents labeled as a package (tar Command), and then use compression program to compress (gzip bzip2 command).

Linux, the most common procedure is to tar the package, use the tar program to break out of the bag package we often referred to as tar, tar package file commands are usually ending with .tar. After generating tar package, you can use other procedures to be compressed.

1. gzip tool
Syntax: gzip [-d #] filename where # is the number 1-9, default compression level 6
Only archive
-f archive mandatory coverage
-1 Fast file compression
-9 Best archive
-v visual compression
gzip filename generated source files disappear filename.gz
After extracting gzip -d filename.gz decompression, compressed files will disappear
zcat to view gzip compressed package

Best compression and decompression

[Root @ localhost tmp] # gzip -9 a.img
[Root @ localhost tmp] # ls -lk
-rw -------. 1 root root 16507 Mar 26 13:00 a.img.gz
[Root @ localhost tmp] # gzip -d a.img.gz
[Root @ localhost tmp] # ls -lk
-rw -------. 1 root root 16568 Mar 26 13:00 a.img

You can compress multiple files gzip file1 file2 file3
1234 [root @ localhost tmp] # gzip a.img dhcp-4.3.1.tar
[Root @ localhost tmp] # ls -l
-rw -------. 1 root root 16902566 Mar 26 13:00 a.img.gz
-rwxr-xr-x. 1 root root 8987298 Mar 26 12:58 dhcp-4.3.1.tar.gz

Visualization compression
[Root @ localhost tmp] # gzip -v dhcp-4.3.1.tar
dhcp-4.3.1.tar: 33.5% - replaced with dhcp-4.3.1.tar.gz

2. bzip2 compression tool
Syntax: bzip2 [-dz] filename
Compression, you can add "-z" also can not add, can be compressed files
bzip2 filename generated source files disappear filename.bz2
It does not support compression directory

-d forced decompress files
-z force compression file, the default can not add
-k Keep the original file compression
-f Force overwrite the original file is decompressed
-v visual compression, displays the percentage, the size before and after compression to save space;
After bzip2 -d filename.bz2 extracting archive files disappear
You can use the contents of the file bzcat view bz2 after compression

You can compress multiple files bzip2 file1 file2

[Root @ localhost tmp] # bzip2 a.img
[Root @ localhost tmp] # ls -l
-rw -------. 1 root root 17025434 Mar 26 13:00 a.img.bz2
[Root @ localhost tmp] # bzip2 -v dhcp-4.3.1.tar
  dhcp-4.3.1.tar: 1.538: 1, 5.200 bits / byte, 35.00% saved, 13506560 in, 8779359 out.

Forced covering the source file to keep the source file compression, decompression

[Root @ localhost tmp] # bzip2 -k a.img
[Root @ localhost tmp] # ls -lh
-rw -------. 1 root root 17M Mar 26 13:00 a.img
-rw -------. 1 root root 17M Mar 26 13:00 a.img.bz2
[Root @ localhost tmp] # bzip2 -dfv a.img.bz2
  a.img.bz2: done
[Root @ localhost tmp] # ls -lh
drwxr-xr-x. 2 root root 4.0K Mar 27 13:38 abc
-rw -------. 1 root root 17M Mar 26 13:00 a.img

3. xz
Usage with gzip and bzip2
xz filename generation filename.xz
It does not support compression directory

-v visual compression, compression show progress and time spent;
xz -d filename.xz decompress
xcat to view the contents of the package xz compressed

Multiple directories can compress, decompress multiple directories, and visualization;
[Root @ localhost tmp] # xz a.img dhcp-4.3.1.tar
[Root @ localhost tmp] # ls -lh
-rw -------. 1 root root 17M Mar 26 13:00 a.img.xz
-rwxr-xr-x. 1 root root 8.0M Mar 26 12:58 dhcp-4.3.1.tar.xz
[Root @ localhost tmp] # xz -dv a.img.xz dhcp-4.3.1.tar.xz
a.img.xz (1/2)
  100.0% 16.1 MiB / 16.2 MiB = 0.997
dhcp-4.3.1.tar.xz (2/2)
  100.0% 8,146.0 KiB / 12.9 MiB = 0.618

4. zip and unzip
zip is a compression tool, unzip a decompression tool, you need to install before you can use.

The command to install zip: yum install -y zip
The command to install unzip: yum install -y unzip
-v visual display of the compression process, showing before and after compression file size and compression percentage;
When using the -d decompress, unzip to specify which directory;
Not decompress multiple files simultaneously, do not support the -v decompress visualization;

Compressed files: zip filename.zip filename
Archive directory: zip -r dir.zip dir /
Unzip the zip package: unzip filename.zip


Compression abc directory ab.zip, ab.zip and decompress compressed to a specified directory under ab, abc entire catalog extract to ab directory;
[Root @ localhost tmp] # zip -r ab.zip abc /
  adding: abc / (stored 0%)
  adding: abc / passwd (deflated 58%)
[Root @ localhost tmp] # unzip ab.zip -d ab
Archive: ab.zip
  creating: ab / abc /
  inflating: ab / abc / passwd
  inflating: ab / abc / a.img
[Root @ localhost tmp] # ls -lh
drwxr-xr-x. 3 root root 4.0K Mar 27 15:30 ab
drwxr-xr-x. 2 root root 4.0K Mar 27 15:27 abc
-rw-r - r-- 1 root root 17M Mar 27 15:25 ab.zip.
[Root @ localhost tmp] # ls -l ab /
drwxr-xr-x. 2 root root 4096 Mar 27 15:24 abc
[Root @ localhost tmp] # ls -l ab / abc /
-rw -------. 1 root root 16965117 Mar 27 15:24 a.img
-rw-r - r-- 1 root root 1019 Mar 27 13:23 passwd.

You can use the file name.gz name.zip Discover what kind of compressed file compression format;

5. tar Strapping Tools

Packaging can also be packaged file directory
Syntax: tar [-zjxcvfpP] filename
Packing: tar -cvf test.tar test is a test where a file or directory
-c indicates that the established package
-v visualization process of packing
-f compression with "-f filename", meaning that the compressed file named filename, when extracting with "-f filename", meaning unzip filename. Please note, if it is the case of multiple parameters in combination with there are "-f", see the "-f" written last.
-z packaged while using gzip compression
-j packaged simultaneously compressed with bzip2
-J Packaged use xz compression
-C Specified directory after extracting
tar -C / tmp / -xvf 1.tar extract to the specified directory / tmp inside

Check the package contents: tar -tf test.tar
-t Check tar package inside the file
See also use tar -tf compressed package: tar -tf 1.tar.gz or tar -tf 1.tar.bz2

Unpack: tar -xvf test.tar
-x unpack or unzip
Whether packing or unpacking, the original file is not deleted, but it will overwrite the current file or directory that already exists.

Abc.tar packaged abc directory, view the contents of abc.tar, extract abc.tar package;

[Root @ localhost tmp] # ls -l
drwxr-xr-x. 2 root root 4096 Mar 27 15:27 abc
-rw -------. 1 root root 16965117 Mar 26 13:00 a.img
-rwxr-xr-x. 1 root root 13506560 Mar 26 12:58 dhcp-4.3.1.tar
[Root @ localhost tmp] # tar -cvf abc.tar abc
abc /
abc / passwd
abc / a.img
[Root @ localhost tmp] # tar -tf abc.tar
abc /
abc / passwd
abc / a.img
[Root @ localhost tmp] # tar -xvf abc.tar
abc /
abc / passwd
abc / a.img

At the same package multiple files to 11.tar
[Root @ localhost tmp] # tar -cvf 11.tar abc a.img dhcp-4.3.1.tar abc.tar
abc /
abc / passwd
abc / a.img
a.img
dhcp-4.3.1.tar
abc.tar
[Root @ localhost tmp] # ls -lh
-rw-r -. r-- 1 root root 62M Mar 27 16:33 11.tar


While packaged compressed with gzip: tar -czvf 1.tar.gz 1 wherein 1 may also be a file directory
-z indicates package while using gzip compression
Unzip .tar.gz archive: tar -xzvf 1.tar.gz
Use bzip2 compression: tar -cjvf 1.tar.bz2 1
-j represents packaged simultaneously compressed with bzip2
Unzip .tar.bz2: tar -xjvf 1.tar.bz2


Use gzip compressed and packed using bzip2 compression and packaging, compared to 2 compression format, bzip2 compressed file is smaller; use xz compression, the best results! The smallest compressed file!
The source file is 13M, after gzip compression to 8.6M, after bzip2 compressed 8.4M, after xz compressed 8.0M;

[Root @ localhost tmp] # ls -lh
-rwxr-xr-x. 1 root root 13M Mar 26 12:58 dhcp-4.3.1.tar
[Root @ localhost tmp] # tar -czvf gzip.tar.gz dhcp-4.3.1.tar dhcp-4.3.1.tar
[Root @ localhost tmp] # tar -cjvf bzip2.tar.bz2 dhcp-4.3.1.tar dhcp-4.3.1.tar
[Root @ localhost tmp] # ls -lh
-rw-r -. r-- 1 root root 8.4M Mar 27 16:54 bzip2.tar.bz2
-rwxr-xr-x. 1 root root 13M Mar 26 12:58 dhcp-4.3.1.tar
-rw-r -. r-- 1 root root 8.6M Mar 27 16:54 gzip.tar.gz
[Root @ localhost tmp] # xz dhcp-4.3.1.tar
[Root @ localhost tmp] # ls -lh
-rw-r -. r-- 1 root root 8.4M Mar 27 16:54 bzip2.tar.bz2
-rwxr-xr-x. 1 root root 8.0M Mar 26 12:58 dhcp-4.3.1.tar.xz
-rw-r -. r-- 1 root root 8.6M Mar 27 16:54 gzip.tar.gz

Sometimes we see a kind of file name suffix .tar.xz, which is compressed with xz compression tool,

Packaged compressed into xz format archive: tar -cJvf dir.tar.xz dir /
Decompression method: tar -Jxvf file.tar.xz

When packing can exclude certain files or directories to add parameters --exclude
tar --exclude 1.txt -czvf 1.tar.gz dir /
Exclude multiple files or directories: tar --exclude "directory name" --exclude "* filename" -czvf 1.tar.gz dir /

Package root directory to exclude directories 1.tar.gz and install inside the beginning of the file;

[Root @ localhost ~] # tar -czvf 1.tar.gz --exclude "install *" / root /
     
         
         
         
  More:      
 
- Linux system security configuration (Linux)
- Why do you need close contact Rust 1.0 (Programming)
- Linux System Getting Started Learning: The Linux log (Linux)
- Linux data recovery software efficiently practical application extundelete (Linux)
- CentOS achieve trash mechanism (Linux)
- Android use canvas board painting (Programming)
- Seven kinds of NIC binding mode Detail (Linux)
- Ubuntu15 core CLR (Server)
- Build your own Web server under Ubuntu Linux system (Server)
- PHP call a Python program (Programming)
- Install JDK 1.7 + Eclipse in CentOS 6.4 in (Linux)
- Docker in the development and practice of IFTTT (Server)
- How to Install Android Studio on Ubuntu 15.04 / CentOS7 (Linux)
- Use IP address spoofing Intrusion Prevention Firewall (Linux)
- MySQL backup tool to back up mydumper (Database)
- How to enhance the security of Linux systems (Linux)
- Ubuntu 14.04 LTS installed Hadoop 1.2.1 (distributed cluster mode) (Server)
- How to use Java to read OpenOffice document (Programming)
- MySQL time field based partitioning scheme summary (Database)
- Android Studio quick overview of Gradle (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.