Linux compression and decompression files

gzip /gunzip

Syntax:
gzip file (compressed file, you can only compress the file into .gz file)
gunzip
file.gz decompress file Example: Use gzip command to compress blog.txt file, and then decompress it with gunzip
Insert picture description here

Note: When using gzip /gunzip, the original file will not be left

zip/ unzip

Syntax:
zip [options] zipedName.zip the directory to be compressed (-r: recursive compression, compress the entire directory)
unzip [options] the file to be decompressed (-d directory specifies the decompressed directory)

Example 1: Use zip to compress the files in the home directory into a homefiles.zip file
Insert picture description here
Example 2: Use unzip to unzip the homefiles.zip file to the /home/newfile directory
Insert picture description here

Packaging command tar

The tar command can create archives for linux files and directories. Using tar, you can create an archive (backup file) for a particular file, you can also change the file in the archive, or add new files to the archive. With the tar command, a large number of files and directories can be packaged into one file, which is very useful for backing up files or combining several files into one file for network transmission.
First of all, we must clarify two concepts: packaging and compression. Packaging refers to turning a large number of files or directories into a total file; compression refers to turning a large file into a small file through some compression algorithms.
Why distinguish between these two concepts? This is due to the fact that many compression programs in Linux can only compress a file, so when you want to compress a large number of files, you have to pack the large number of files into a package (tar command), and then use Compressor for compression (gzip bzip2 command)

Syntax:
tar [parameter] zipedName.tar.zp The content to be packaged (packaged file, the format after packaging is tar.zp)

parameter Description
-A Add files to existing backup files
-B Create a new backup file
-C <directory> This option is used for decompression, if you want to decompress in a specific directory, you can use this option.
-d Differences in recording files
-x Restore files from backup files
-t List the contents of the backup file
-from Process backup files through gzip instructions
-FROM Process the backup file through the compress command
-f <backup file> Specify the backup file
-r Add files to already compressed files
-u Add changed and existing files to existing compressed files
-j Support bzip2 to decompress files
-l File system boundary settings
-k Keep the original file without overwriting
-m Keep files from being overwritten
-w Confirm the correctness of the compressed file
-p Restore files with original file permissions
-P The file name uses an absolute name and does not remove the "/" sign before the file name
-N <date format> Only save files that are newer than the specified date to the backup file
--Exclude=<template style> Exclude files that match the template style
-c Generate tar package file
-v Display detailed execution information
-f Specify the compressed file name
-from Pack and compress at the same time
-x Unzip the tar file

Example:
1 Add a.txt, b.txt, c.txt to the package and compress it to the file dabao.tar.gz
Insert picture description here
2 Unzip dabao.tar.gz to the /home/test directory
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43705953/article/details/108019035