[Linux] File compression related commands (for personal use)

1. Common file compression formats

The compressed file formats under Windows and Linux have some common and some differences. Here are some common compressed file formats:

  • .zip : This is the most commonly used compression format in Windows, and it is also a compression format that can be recognized in Linux. It can easily compress files with Windows systems. In Linux, you can use the zip and unzip commands to compress and decompress .zip files.
  • .rar : This is another commonly used compression format in Windows, but this format is not supported in Linux, you need to install the rar or unrar package to compress and decompress .rar files.
  • .7z : This is a high-compression format that can be used to compress and decompress .7z files using the 7-Zip software in Windows and Linux.
  • .gz : This is a commonly used compression format in Linux. You can use the gzip and gunzip commands to compress and decompress .gz files. Note that the .gz format can only compress a single file and cannot pack multiple files or directories.
  • .bz2 : This is another commonly used compression format in Linux. You can use the bzip2 and bunzip2 commands to compress and decompress .bz2 files. Note that the .bz2 format can only compress a single file, not a directory.
  • .tar : This is a commonly used packaging format in Linux. You can use the tar command to package multiple files or directories into a .tar file. Note that the .tar format can only be packaged, not compressed.
  • .tar.gz and .tar.bz2 : These are two commonly used packaging and compression formats in Linux. You can use the tar command in conjunction with the -z or -j option to package and compress multiple files or directories into one .tar.gz or .tar.bz2 files.

2. Overview of file compression commands under Linux

In Linux, there are several commonly used file compression commands, including:

  1. tar: Used to create and extract tar archives. It is often used with other compression algorithms such as gzip or bzip2 to produce compressed files such as .tar.gz or .tar.bz2. Here are some examples of commonly used tar commands:

    • Create a tar archive:tar -cvf archive.tar file1 file2 file3
    • Extract the tar archive:tar -xvf archive.tar
    • Create a tar.gz compressed file:tar -czvf archive.tar.gz file1 file2 file3
    • Extract the tar.gz compressed file:tar -xzvf archive.tar.gz
  2. gzip: Used to create and extract gzip compressed files. It compresses a single file and changes its extension to .gz. Here are some examples of commonly used gzip commands:

    • Compressed file:gzip file
    • Unzip the file: gzip -d file.gzorgunzip file.gz
  3. bzip2: Used to create and extract bzip2 compressed files. Similar to gzip, it also compresses a single file and changes its extension to .bz2. Here are some examples of commonly used bzip2 commands:

    • Compressed file:bzip2 file
    • Unzip the file: bzip2 -d file.bz2orbunzip2 file.bz2
  4. zip: Used to create and extract ZIP archives. ZIP is a common cross-platform compression format that can contain multiple files and directories. Here are some examples of commonly used zip commands:

    • Compress a file or directory:zip archive.zip file1 file2 dir1
    • Extract the ZIP file:unzip archive.zip

This is commonly used, and of course there are other commands as well.

3. Detailed description

This section will introduce in detail the commonly used file compression commands in the Linux operating system, including tar, gzip, bzip2, and zip. These commands provide a wealth of features for creating and extracting compressed files, helping you manage files and directories efficiently and save storage space.

1. tar command

tar (tape archive) is one of the most commonly used file packaging and compression tools in Linux. It can pack multiple files and directories into a single file and preserve file permissions, owner information, etc. The tar command is often used in conjunction with other compression algorithms, such as gzip or bzip2, to produce compressed files such as .tar.gz or .tar.bz2.

Parameter explanation:

  • -c: Create a new tar archive.
  • -v: Displays a list of compressed or decompressed files.
  • -f: Specifies the compressed or decompressed file name.
  • -x: Extract files from a tar file.
  • -z: Compress or decompress using gzip.
  • -j: Use bzip2 for compression or decompression.

Basic usage:

  • Create a tar archive:
    tar -cvf archive.tar file1 file2 file3
    
  • Extract the tar archive:
    tar -xvf archive.tar
    
  • Create a tar.gz compressed file:
    tar -czvf archive.tar.gz file1 file2 file3
    
  • Extract the tar.gz compressed file:
    tar -xzvf archive.tar.gz
    

2. gzip command

gzip is a commonly used file compression tool for compressing individual files. It compresses files in .gz format and can restore to original files.

Parameter explanation:

  • -d: Unzip the file.
  • -c: Output the compression result to standard output without modifying the original file.

Basic usage:

  • Compressed file:
    gzip file
    
  • Unzip the file:
    gzip -d file.gz
    
    or
    gunzip file.gz
    

3. bzip2 command

bzip2 is another commonly used file compression tool, similar to gzip. It uses a more efficient compression algorithm and produces compressed files with a .bz2 extension.

Parameter explanation:

  • -d: Unzip the file.
  • -k: Keep the original file.

Basic usage:

  • Compressed file:
    bzip2 file
    
  • Unzip the file:
    bzip2 -d file.bz2
    
    or
    bunzip2 file.bz2
    

4. zip command

The zip command is used to create and extract ZIP archives, a cross-platform compression format that can contain multiple files and directories.

Parameter explanation:

  • -r: Recursively compress directories and their contents.
  • -d: Delete the specified file or directory from the ZIP file.

Basic usage:

  • Compress a file or directory:
    zip archive.zip file1 file2 dir1
    
  • Extract the ZIP file:
    unzip archive.zip
    


Write love you forever into the end of the poem ~

Guess you like

Origin blog.csdn.net/weixin_43764974/article/details/131485010