Skip to content

[Linux] Compression, Encrypted compression, Split compression, Decompression

There are many kinds of compression instructions in Linux., sometimes it’s really difficult to remember all.

Therefore, I want to record some commonly used instructions of compression, encryption compression, partition compression, and decompression.

In Linux OS, common compressed file format are:

  • 7z
  • bz2
  • gz
  • rar
  • xz
  • Z
  • zip
  • tar
  • tar.bz2
  • tar.gz
  • tar.xz
  • tar.Z

There are many different compression instructions in Linux, corresponding to different compression algorithms.

Let’s see them step by step!


7z

7z is an open source compression program, it is developed by Igor Pavlov in 1999. You can see more information in SourceForge: https://sourceforge.net/projects/sevenzip/files/7-Zip/

Compression: 7z a File.7z File
Encrypted compression: 7z a File.7z File -p{dddd}
Split compression: 7z -v{dddd}m a File.7z File
Decompression: 7z x File.7z

The {dddd} part is where the numbers are entered.


bz2

“bzip2” is developed by Julian Seward, and it is also a compression algorithm.

It is not a file archive utility that takes a number of files, so it can’t puts them into a single binary file. If we want to do it, maybe we need “tar.bz2”.

Compression: bzip2 -z File
Decompression: bzip2 -d File.bz2

gz

Gzip introduction from Wiki

gzip is a file format and a software application used for file compression and decompression. The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program used in early Unix systems, and intended for use by GNU (the “g” is from “GNU”). Version 0.1 was first publicly released on 31 October 1992, and version 1.0 followed in February 1993. Note that gzip is a compression format rather than an archive format. [2]

As with bzip2, we cannot compress and encrypt folders, and must be used with tar if necessary.

Compression: gzip File
Decompression: gzip -d File.gz

rar

RAR introduction from Wiki

RAR is a proprietary[3] archive file format that supports data compressionerror recovery and file spanning. It was developed by a Russian software engineer, Eugene Roshal (the name RAR stands for Roshal Archive) and the RAR software is licensed by win.rar GmbH.[3]

This is not to be confused with the unrelated Resource Adapter Archive file format which is also spelled “.rar”.[4][5][6][7][8][9]

Basically, rar likes 7z, or 7z likes rar, you can perform operations such as encryption, segmentation, and so on.

Comression: rar a -r File.rar File
Encrypted compression: rar a -r File.rar File -p{dddd}
Split compression: rar a -r -v{dddd}m File.rar File
Decompression: rar x File.rar

{dddd} is the part where numbers can be entered.


xz

XZ introduction from Wiki

xz, a lossless data compression file format based on the LZMA algorithm, often with the file extension “.xz”XZ Utils, a set of free lossless data compressors, including the command xz
Compression: xz -z File
Decompression: xz -d File.xz

Z

The ending “.Z” extension I must honestly say I have never encountered. The reason why it is written is because the relevant information happened to be found at the time of writing this note.

Basically, this is the file compression extension for Linux compress, which can be compressed and decompressed using the “compress” command of the Linux command.

Compression: compress File
Decompression: compress -d File

zip

ZIP introduction from Wiki

ZIP is an archive file format that supports lossless data compression. A ZIP file may contain one or more files or directories that may have been compressed. The ZIP file format permits a number of compression algorithms, though DEFLATE is the most common. This format was originally created in 1989 and released to the public domain on February 14, 1989 by Phil Katz, and was first implemented in PKWARE, Inc.‘s PKZIP utility,[2] as a replacement for the previous ARC compression format by Thom Henderson. The ZIP format was then quickly supported by many software utilities other than PKZIP. Microsoft has included built-in ZIP support (under the name “compressed folders”) in versions of Microsoft Windows since 1998. Apple has included built-in[3] ZIP support in Mac OS X 10.3 (via BOMArchiveHelper, now Archive Utility) and later. Most free operating systems have built in support for ZIP in similar manners to Windows and Mac OS X.
ZIP files generally use the file extensions .zip or .ZIP and the MIME media type application/zip.[1] ZIP is used as a base file format by many programs, usually under a different name. When navigating a file system via a user interface, graphical icons representing ZIP files often appear as a document or other object prominently featuring a zipper.
Compression: zip -r File.zip File
Encrypted compression: zip -rP {dddd} test.zip words.txt
Decompression: unzip File.zip

tar

tar introduction from Wiki

In computingtar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from (t)ape (ar)chive, as it was originally developed to write data to sequential I/O devices with no file system of their own. The archive data sets created by tar contain various file system parameters, such as name, time stamps, ownership, file access permissions, and directory organization. The command line utility was first introduced in the Version 7 Unix in January 1979, replacing the tp program.[2] The file structure to store this information was standardized in POSIX.1-1988[3] and later POSIX.1-2001,[4] and became a format supported by most modern file archiving systems.
Compression: tar -cvf File.tar File
Decompression: tar -xvf File.tar

tar.bz2

This type of file basically is to further compress the tar file into a bzip2 file, so the archive compression that could not be performed originally (see the part of bz2 above) is logically implemented.

Compression: tar -jcvf File.tar.bz2 File
Decompression: tar -jxvf File.tar.bz2

tar.gz

Same as tar.bz2 above, except that the further compressed file is in gzip format.

Compression: tar -zcvf File.tar.gz File
Decompression: tar -zxvf File.tar.gz

tar.xz

The same version of xz as above.

Compression: tar -Jcvf File.tar.xz File
Decompression: tar -Jxvf File.xz

tar.Z

The same version of Z as above.

Compression: tar -Zcvf File.tar.Z File
Decompression: tar -Zxvf File.tar.Z

References

Tags:

Leave a Reply