The article directories
- 1. Compress and decompress commands
-
- 1.1 Gzip/gunzip instruction
- 1.2 zip/unzip instructions
- 1.3 the tar command
1. Compress and decompress commands
1.1 Gzip/gunzip instruction
gzip
Used to compress files,gunzip
Decompression- The basic grammar
Gzip file
(Function description: Compressed file, can only be compressed as*.gz
File)
Gunzip file. Gz
(Function description: Decompress file command) - Examples of application
- Case 1:
gzip
Compression,/home
Under thehello.txt
File compression
gzip /home/hello.txt
Copy the code
- Case 2:
gunzip
Compression,/home
Under thehello.txt.gz
Decompress the file
1.2 zip/unzip instructions
zip
Used to compress files,unzip
For decompression, this is useful in packaged project releases- The basic grammar
Zip [option] xxx.zip
What to compress (Function Description: Commands to compress files and directories)
Unzip [option] xxx.zip
(Function description: Decompress files) - Zip Common options
-r
: Recursive compression, that is, compressed directory - Unzip Common option
-d
< directory >: specifies the directory for storing decompressed files - Examples of application
- Case 1: will
/home
Under all files/folders are compressed intomyhome.zip
Zip -r myhome.zip /homeCopy the code
- Case 2: will
myhome.zip
unzip/opt/tmp
directory
mkdir /opt/tmp
unzip -d /opt/tmp /home/myhome.zip
Copy the code
1.3 the tar command
tar
The directive is the package directive, and the last packaged file is.tar.gz
The file.- The basic grammar
Tar [option] xxx.tar. gz Package content
(Function description: Package a directory in compressed format. Tar.gz)√ Option Description - Option to show
- Examples of application
- Case 1: Compressing multiple files will
/home/pig.txt
and/home/cat.txt
Compressed intopc.tar.gz
tar -zcvf pc.tar.gz /home/pig.txt /home/cat.txt
Copy the code
- Case 2: Compress the /home folder into myhome.tar.gztar-zcvf myhome.tar.gz /home/
tar -zcvf myhome.tar.gz /home/
Copy the code
- Case 3: Decompress pc.tar.gz to the current directory, tar -zxvf pc.tar.gz
tar -zxvf pc.tar.gz
Copy the code
- Case 4: will
myhome.tar.gz
unzip/opt/tmp2
directory
(1)mkdir /opt/tmp2
(2)tar -zxvf /home/myhome.tar.gz -C /opt/tmp2