Home >Operation and Maintenance >Linux Operation and Maintenance >The most complete commands for compressing and decompressing zip, gz, tar, and bz2 files under Linux (detailed step-by-step instructions with pictures and texts)

The most complete commands for compressing and decompressing zip, gz, tar, and bz2 files under Linux (detailed step-by-step instructions with pictures and texts)

韦小宝
韦小宝Original
2018-07-13 10:50:535403browse

Everyone knows that compressing and decompressing files under win is very simple and convenient. So under Linux, the most commonly used one is the command line. Compressing and decompressing files has become a not easy task. So how to compress files into zip, gz, tar, bz2 format under Linux system? How to decompress zip, gz, tar, bz2 compressed files under Linux system? What command needs to be executed? The following is the most complete picture and text explanation of compression and decompression methods under Linux summarized by PHP Chinese website!

zip format compression and decompression

#压缩文件和目录
zip【压缩文件名】【源文件】 #压缩文件
zip -r 【压缩文件名】【源目录】 #压缩目录
#解压文件和目录
unzip【压缩文件名】 #解压

gz format compression and decompression

#压缩文件和目录
gzip【源文件】 #压缩为 gz格式的压缩文件,源文件会消失
gzip -c【源文件】>【压缩文件】 #压缩为gz格式,源文件保留gzip -c cangls > cangls.gz #上面的例子
gzip -z【目录】 #压缩目录下所有的子文件,但是不能压缩目录
#解压文件
gunzip 【压缩文件名】gzip -d 【压缩文件名】
#以上两种解压是一样的

bz2 format compression and decompression

Note: bzip2 command cannot compress directories

#压缩文件
bzip2【源文件】 #压缩为.bz2格式,不保存源文件
bzip2 -k【源文件】 #压缩之后保留源文件
#解压文件
bunzip2 【压缩文件名】gzip -d 【压缩文件名】
#以上两种解压是一样的

tar packaging command

tar -cvf [package file name] [source file]

options

  • - c: Packed

  • -z: Compressed into .tar.gz format

  • -j: Compressed into .tar.bz2 format

  • -t: View

  • -x: Unpack

  • -v: Show process

  • -f: Specify the packaged file name

#例如
tar -zcvf cangls.tar cangls #打包为.tar.gz格式
tar -jxvf cangls.tar #解.tar.bz2格式的打包

Note: Without -z or -j, it is packaged or decompressed in .tar format

The above is the detailed content of The most complete commands for compressing and decompressing zip, gz, tar, and bz2 files under Linux (detailed step-by-step instructions with pictures and texts). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn