One, compression command [COMPRESS/GZIP/BZIP2]:
Compression can only be done on files, not directories, directories to be packaged first, and then compressed.
(1) Compress
(2) Gzip
1. Compress files
[CPP]View PlainCopy
- Gzip hosts #将hosts压缩成hosts. GZ, do not retain the original file
- Gzip-c hosts > Xx/hosts.gz #将hosts压缩成hosts. GZ, preserves the original file, and can also specify a path
2. View Compressed file contents
[CPP]View PlainCopy
- Zcat hosts.gz
3. Decompression
[CPP]View PlainCopy
- Gzip-d hosts.gz #不指定路径的解压, unzip to the current directory, do not retain the compressed file
- Gzip-d-C hosts.gz > Xx/hosts #指定路径的解压 while preserving compressed files
(3) bZIP
1. Compress files
[CPP]View PlainCopy
- Bzip2 hosts.bz2 #将hosts压缩成hosts. bz2, do not keep the original file
- Bzip2-c hosts > xx/hosts.bz2 #将hosts压缩成hosts. GZ, retains the original file, and can also specify the path <span style="FONT-SIZE:18PX;" >
- </span>
2. View Compressed file contents
[CPP]View PlainCopy
- Bzcat hosts.bz2
3. Decompression
[CPP]View PlainCopy
- Bzip2-d hosts.bz2 #不指定路径的解压, unzip to the current directory, do not retain the compressed file
- Bzip2-d-C hosts.bz2 > Xx/hosts #指定路径的解压 while preserving compressed files
Summarize:
-C: Specify path, keep file
-D: Unzip
gzip, bzip2 default does not retain the original file/compressed file.
Ii. Packing/compressing commands [tar]
2.1 Packing/Unpack:
(1) Package a single file
[CPP]View PlainCopy
- Tar cvf aa.tar AA #默认保留原文件
- Tar cvf aa.tar aa--remove-file #打包后删除原文件
(2) Packaging multiple files
[CPP]View PlainCopy
- Tar cvf ab.tar aa bb #默认保留原文件
- Tar cvf aa.tar aa bb--remove-file #打包后删除原文件
(3) View the contents of the package
[CPP]View PlainCopy
- Tar TVF Aa.tar
(4) Unpacking
[CPP]View PlainCopy
- Tar xvf Aa.tar #不指定路径的解包, unpack to current directory
- Tar xvf aa.tar-c xx/aa #指定路径的解包
2.2 Package and compress/unzip and unpack:
In gzip format
(1) Package a single file and compress
[CPP]View PlainCopy
- Tar zcvf aa.tar.gz AA #保留原文件
- Tar zcvf aa.tar.gz aa--remove-file #不保留原文件
(2) Packaging multiple files and compressing
[CPP]View PlainCopy
- Tar zcvf ab.tar.gz aa bb #保留原文件
- Tar zcvf ab.tar.gz aa bb--remove-file #不保留原文件
(3) Decompression
[CPP]View PlainCopy
- Tar zxvf ab.tar.gz #不指定路径解压, unpacking
- Tar zxvf ab.tar.gz-c xx/ab #指定路径解压, unpacking
In BIZP2 format
(1) Package a single file and compress
[CPP]View PlainCopy
- Tar jcvf aa.tar.bz2 AA #保留原文件
- Tar jcvf aa.tar.bz2 aa--remove-file #不保留原文件
(2) Packaging multiple files and compressing
[CPP]View PlainCopy
- Tar jcvf ab.tar.bz2 aa bb #保留原文件
- Tar jcvf ab.tar.bz2 aa bb--remove-file #不保留原文件
(3) Decompression
[CPP]View PlainCopy
- Tar jxvf ab.tar.bz2 #不指定路径解压, unpacking
- Tar jxvf ab.tar.bz2-c xx/ab #指定路径解压, unpacking
Summarize:
-C: Specify the path
--remove-file: Delete the original file
The tar command retains the original file by default.
Package and compress files or directories under Linux