In Linux operating system, the compression and decompression of *.zip, *.tar, *.tar.gz, *.tar.bz2, *.tar.xz, *.jar, *.7z and other formats
zip format
Compress: zip -r [ target file name ] .zip [ original file/directory name ] Unzip: unzip [ original file name ] .zip
Note: -r parameter stands for recursion
tar format (this format is only packaged, not compressed)
Packing: tar -cvf [ target file name ] .tar [ original file name/directory name ] Unpacking: tar -xvf [ original file name ] .tar
Note: The c parameter represents create (create), the x parameter represents extract (unpacking), the v parameter represents verbose (detailed information), and the f parameter represents filename (file name), so the file name must be followed by f.
tar.gz format
Method 1: Use the tar file that has been packaged before, and use the compression command directly.
Compression: gzip [ original filename ] .tar Unzip: gunzip [ original file name ] .tar.gz
Method 2: One-time packaging and compression, decompression and unpacking
Pack and compress: tar -zcvf [ target file name ] .tar.gz [ original file name/directory name ] Extract and unpack: tar -zxvf [ original file name ] .tar.gz
Note: z stands for compression/decompression with gzip algorithm.
tar.bz2 format
Method 1: Use the packaged tar file to directly execute the compression command:
Compression: bzip2 [ original filename ] .tar Unzip: bunzip2 [ original file name ] .tar.bz2
Method 2: One-time packaging and compression, decompression and unpacking
Pack and compress: tar -jcvf [ target file name ] .tar.bz2 [ original file name/directory name ] Extract and unpack: tar -jxvf [ original file name ] .tar.bz2
Note: lowercase j represents compression/decompression with bzip2 algorithm.
tar.xz format
Method 1: Use the packaged tar file and use the compression command directly:
Compression: xz [ original filename ] .tar Unzip: unxz [ original file name ] .tar.xz
Method 2: One-time packaging and compression, decompression and unpacking
Pack and compress: tar -Jcvf [ target file name ] .tar.xz [ original file name/directory name ] Extract and unpack: tar -Jxvf [ original file name ] .tar.xz
Note: Capital J represents compression/decompression with the xz algorithm.
tar.Z format (obsolete)
Method 1: Use the packaged tar file and use the compression command directly:
Compression: compress [ original filename ] .tar Unzip: uncompress [ original file name ] .tar.Z
Method 2: One-time packaging and compression, decompression and unpacking
Pack and compress: tar -Zcvf [ target file name ] .tar.Z [ original file name/directory name ] Extract and unpack: tar -Zxvf [ original file name ] .tar.Z
Note: Capital Z stands for compression/decompression with the ncompress algorithm. In addition, ncompress is the compression format of early Unix systems, but because the compression rate of ncompress is too low, it is now outdated.
jar format
Compression: jar -cvf [ target file name ] .jar [ original file name/directory name ] Decompression: jar -xvf [ original file name ] .jar
Note: If the package is a Java class library, and there is a main class in the class library, then you need to write a META-INF/MANIFEST.MF configuration file, the content is as follows:
Manifest-Version: 1.0 Created-By: 1.6.0_27 (Sun Microsystems Inc.) Main-class: the_name_of_the_main_class_should_be_put_here
Then package it with the following command:
jar -cvfm [ target file name ] .jar META-INF/MANIFEST.MF [ original file name/directory name ]
In this way, the "java -jar [file name].jar" command can be used to directly run the public static void main method in the main class.
7z format
Compression: 7z a [ destination filename ] .7z [ original filename/directory name ] Decompression: 7z x [ original filename ] .7z
Note: This 7z decompression command supports rar format, namely:
7z x [ original file name ] .rar