Compression and decompression of files under Linux

1. zip format

        zip is probably the most used document compression format today. Its biggest advantage is that it can be used on different operating system platforms. The downside is support

The compression ratio is not very high, while tar.gz and tar.bz2 do a very good job in terms of compression ratio.

        We can compress a file with the following command:

        zip -r archive_name.zip filename (-r is the compressed file)

       Here's how to unzip a zip file:

        unzip archive_name.zip (the unzip file is under the current file)

        unzip archive_name.zip -d new_dir (unzip the file can unzip the file to a directory you specify, use the -d parameter)

2. tar format

     tar is a very widely used documentation packaging format in Linux. Its advantage is that it consumes very little CPU and time to pack files, it

Just a packaging tool, not responsible for compression. Here's how to package a directory:

      tar -cvf archive_name.tar directory_to_compress     

      -c parameter is to create a new archive

      The -v parameter shows the processed files in detail

      -f parameter specifies archive or device

      How to unpack after packing:

      tar -xvf archive_name.tar

     The above unpack command will unpack the document in the current directory. Of course, you can also use the following command to unpack to the specified path:

      tar -xvf archive_name.tar -C new_dir (the unpacking parameter is -C, not lowercase c)

3. tar.gz format

     This format is the compression format I use the most. It does not take up too much CPU when compressing, and can get a very ideal compression ratio.
     Compression method:
     tar -zcvf archive_name.tar.gz filename
     Decompression method:
     tar -zxvf archive_name.tar.gz
    The above unpacking command will unpack the file in the current directory. Of course, you can also use the following command to specify the unpacking path:
     tar -zxvf archive_name.tar.gz -C new_dir
Fourth, tar.bz2 format
     This compression format is the best compression rate among all the methods we mentioned of. Of course, this also means that it takes up more CPU than the previous method

with time.
     Compression method:
     tar -jcvf archive_name.tar.bz2 filename

     Decompression method:

     tar -jxvf archive_name.tar.bz2
    The above unpacking command will unpack the archive in the current directory. Of course, you can also use the following command to specify the unpacking path:
     tar -jxvf archive_name.tar.bz2 -C new_dir

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324906563&siteId=291194637