Common compression commands for linux review notes

Please reprint from the source: http://eksliang.iteye.com/blog/2109693

The extension of common compressed files in Linux

*.gz files compressed by the gzip program
*.bz2 files compressed by the bzip program
*.tar The data packaged by the tar program is not compressed
*.tar.gz packaged by tar program and compressed by gzip program
*.tar.bz2 packaged by tar program and compressed by bzip program
*.zip files compressed by the zip program
*.rar rar. Program compressed files

 

unzip与zip

Example 1: Compress the files and directories ending in .txt in the current directory into test.zip

zip test.zip *.txt tmp

 Example 2: View the compressed content in *.zip

unzip -l test.zip

 Example 3: Decompress the *.zip archive

unzip test.zip

 Example 4: Unzip *.zip to the specified directory

unzip test.zip -d ./tmp

 

gzip and zcat

 At present, gzip can unpack files compressed by zip, gzip and other software, and the suffix of files compressed with gzip is internationally unified as *.gz

grammar:
gzip [-cdtv#] filename
zcat *.gz
parameter:
-c: Output compressed data to the screen, which can be processed by data stream redirection;
-d: Decompression parameters;
-t: can be used to verify that a compressed file has no errors;
-v: It can display information such as the compression ratio of the "original file/compressed file";
-#: Compression level, 1 is the fastest, but the compression ratio is the worst, -9 is the slowest, but the compression ratio is the highest, the default is 6;

 Example 1: Compression Example

gzip aa.txt

 Example 2: Decompression Example

gzip -dv aa.txt.gz

 Example 3: Read the content of the .gz compressed file

zcat aa.txt.gz

 Example 4: Compress the file and keep the original file

gzip -c aa.txt > aa.txt.gz

 Although gzip provides a compression level of 1~9, it is very easy to use the default 6. It is recommended to use the default -6 when compressing;

cat can read plain text files, and zcat can read compressed files with plain text compressed

  bzip2 and bzcat If the appearance of gzip is to replace the compression software compress, then the appearance of bzip2 is to replace gzip, because it provides a better compression ratio. Its usage is basically the same as gizp
grammar:
bzip2 [-cdkzv#] filename
bzat *.bz2
parameter:
-c: output the data generated during the decompression process to the screen
-d: decompression parameter
-k: keep the original file when compressing the file, without deleting the original file
-z: compression parameter
-v: When compressing a file, it will display information such as the compression ratio of the original file/compressed file
-#: Compression level, -1 compresses faster, but the compression ratio is the worst, -9 is the slowest, but the compression ratio is the best, the default is 6
 Example 1: Compression Example
# After compressing, the original file will be deleted
bzip2 -z aa.txt
#Keep the original file after compressing
bzip2 -kz bb.txt
 Example 2: View the content of the compressed file
bzcat aa.txt.bz2
 Example 3: Unzip the *.bz2 file
bzip2 -d bb.txt.bz2
 

 package command tar

The gzip and bzip2 described above can only compress a single file. For a directory, multiple files are compressed at the same time. He can't do such operations. What should I do? tar appears. The function of tar is to package a directory or multiple files into a It is a large file, but the packaged file is not compressed, so it is called "packaging command". Multiple files or directories packaged with tar can be compressed using gzip and bzip2.

grammar:
tar [-ctxv] [-jz] [-f filename] filename [-C directory]
Parameter meaning:
-c: Create a new package file, usually with -v to view the file name packaged in the process
-t: View which file names are in the content of the packaged file, focusing on viewing
-x: decompression parameter, usually specified with -C to decompress in a specific directory
#Attention! This is very critical. The three parameters c, t, and x cannot be in a series of commands at the same time.

-j: Compress/decompress with bzip2 support, the compressed file specification is named *.tar.bz2
-z: Compress/decompress with gzip support, the compressed file specification command is *.tar.gz
-v: In the process of compressing and decompressing, display the name of the file being processed
-f: followed by the name of the compressed or decompressed file
-C: Use this parameter to decompress the compressed file in a specific directory (uppercase C) when decompressing

 No need to remember this, anyway, the purpose of my writing this blog is to copy it directly when I use it later, so I take an example-driven way to write this blog

 Example 1: Package with tar alone, package all txt files in the current directory into test.tar

tar -cv -f test.tar ./*.txt

  Example 2: View the contents of the test.tar package

tar -tv -f test.tar

 Example 3: Decompress the tar package

# Extract the tar file to the current directory
tar -xv -f test.tar
#Unzip test.tar to tmp in the current directory
tar -xv -f test.tar -C ./tmp/

 Example 4: The common operation of *.tar.gz, when used, just copy and change the file name and it will be OK

#Package the txt in the current directory into txt.txt.gz, which is compressed by gzip
tar -czv -f txt.tar.gz ./*.txt
#View the files under the *.tar.gz package
tar -tzv -f txt.tar.gz
#Unzip the *.tar.gz file
tar -xzv -f txt.tar.gz
#Extract to the specified directory
tar -xzv -f txt.tar.gz -C ./tmp

 Example 5: Common operations of *.tar.bz2

#Package the txt in the current directory into txt.txt.bz2, which is compressed by bzip2
tar -cjv -f txt.tar.bz2 ./*.txt
#View the files under the *.tar.bz2 package
tar -tjv -f txt.tar.bz2
#Unzip the *.tar.bz2 file
tar -xjv -f txt.tar.bz2
#Extract to the specified directory
tar -xjv -f txt.tar.bz2 -C ./tmp

 

Packaging war package and decompressing war package 

Compress the user file under the current directory and compress user.war in the current directory
jar -cvf user.war ./user
Parameter meaning
-c create war package
-v show process information
-f specifies the JAR file name, usually this parameter is required
-M Do not generate a MANIFEST file of all items, this parameter ignores the -m parameter
-0 This is an Arabic number, which means only packaging and no compression

Unzip the user.war package to the current directory
jar -xvf user.war

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326514214&siteId=291194637