Linux file compression and decompression usage record

Source: Internet
Author: User
Tags gz file unpack

One: Tar (compressible can decompress)

  • The tar command is a reliable way to back up files in a unix/linux system and works in almost any environment, with permissions for all users. But tar itself is just a file packaging tool that only has the ability to compress/unzip files when combined with other tools.
  • The format for compressing a file using the tar command is: tar parameter [main OPTION + secondary option] ' file or directory '
  • Parameter main options
    • -C Create a new profile. Select this option if the user wants to back up a directory or some files.
    • -R appends the file to be archived to the end of the archive file. For example, the user is ready to backup files, and found that there is a directory or some files forgot to back up, you can use this option to append the forgotten directories or files to the backup file.
    • -T lists the contents of the archive to see which files have been backed up.
    • -U update file. That is, replace the original backup file with the new file, if the file you want to update is not found in the backup file, append it to the end of the backup file.
    • -X releases the file from the archive file.
  • Parameter pair Options
    • -B This option is set for the tape drive, followed by a number to indicate the size of the chunk, with a system preset value of 20x512 bytes.
    • -f Specifies the file file name or the device name, this option is usually required, this parameter must be placed at the end, followed by the compressed or decompressed filename.
    • -K saves the file that already exists. For example, restoring a file, encountering the same file during the restore process, does not overwrite it.
    • -M when restoring files, set the modification time of all files to now.
    • -M creates multiple volumes of files for storage on several disks.
    • -V Details the file information processed by tar. Without this option, TAR does not report file information.
    • -W each step requires confirmation.
    • -Z Compress/unzip the file with gzip, plus this option to compress the archive file, but you must also use this option to decompress when restoring.
  • How to use
    • The
    • tar command can package files, generally packaging files when we are accustomed to the packaged file suffix set to. tar
      • package:tar-cvf  ' generate file name '   ' packaged file or directory name '   & nbsp
        • eg:tar-cvf  ' Test.bpm.tar ' test.bpm ' to get the file Test.bpm.tar
        • eg:tar-cvf  '/home/te in the current directory St.bpm.tar '   ' test.bpm ', write file Test.bpm.tar
      • unpack:tar-xvf  ' unpacked file name ' in/home directory  
        • eg:tar-xvf  ' Test.bpm.tar ', get the file in the current directory test.bpm
        • eg:tar-xvf  ' Test.bpm.tar '  -c '/home/', in the/home directory to get the file test.bpm, unpacking to other paths must use the-c parameter
    • The tar command can use the parameter-Z to compress or decompress the file in gzip mode. Generally packaged files We are used to set the packaged file suffix to. tar.gz
      • Compressed file: TAR-CZVF ' file or directory name '
        • EG:TAR-CZVF ' test.bpm.tar.gz ' test.bpm ', get the file in the current directory test.bpm.tar.gz
        • EG:TAR-CZVF '/home/test.bpm.tar.gz ' test.bpm ', get the file in the/home directory test.bpm.tar.gz
      • Unzip file: tar-xzvf ' file or directory name '
        • EG:TAR-XZVF ' test.bpm.tar.gz ', get file in current directory test.bpm
        • EG:TAR-XZVF ' test.bpm.tar.gz '-C '/home/', get the file in the home directory test.bpm
  • Error notification
    • When packing or compressing
      • Error: Carefully refuse to create an empty archive file
      • Cause: No name was specified after packaging or compressing the file
    • When unpacking or unpacking
      • Error: Not found in archive
      • Cause: When you specify the unpacked or unpacked file location, the-c parameter is not used and the file location cannot be specified successfully

II: gzip and Gunzip

  • Gzip: Compress files into files with a. gz suffix
    • The format for compressing a file by using the gzip command is: gzip parameter [options] ' file or directory '
    • Parameters
      • -D Unpack the compressed file;
      • -C writes the output to the standard output and retains the original file.
      • -R Recursive processing, processing all files and subdirectories under the specified directory
      • -F: Forcibly compress the file. Ignores the existence of a file name or a hard connection and whether the file is a symbolic connection;
      • -L: Display version and copyright information;
      • -N: When compressing the file, the original file name and time stamp are not saved;
      • -N: Save the original file name and time stamp when compressing the file;
      • -T: Test that the compressed file is correct;
      • -< compression efficiency;: Compression efficiency is a value between 1~9, the default value is "6", specifying the larger the value, the higher the compression efficiency;
        • --best: The effect of this parameter is the same as specifying the "-9" parameter;
        • --fast: The effect of this parameter is the same as specifying the "-1" parameter.
    • Chestnuts
      • Compress the test.bpm file into the current directory
        • Method One: GZIP-CRF ' test.bpm ' > ' test.bpm.gz '. Get File test.bpm.gz
        • Method Two: Gzip-rf ' test.bpm '. Get File test.bpm.gz
        • Note that the difference between the two methods is that the source file will not disappear after the method one compresses the file, but it will need to specify the compressed file name itself; Method Two compresses the file, the source file disappears, but does not need to specify the compressed file name itself, it will automatically generate a suffix of. gz Files with the same name as the source file
      • Compress the Test.bmp file to the specified directory
        • Gzip CF ' test.bpm ' > '/home/test.bpm.gz '. Get File test.bpm.gz
  • Gunzip: Unzip the suffix. gz file
    • The format for compressing a file by using the gzip command is: gzip parameter [options] ' file or directory '
    • Parameters same as Gzip
    • Chestnuts
      • Extract the test.bpm.gz file to the current directory
        • Method One: GUNZIP-CRF ' test.bpm.gz ' > ' test.bpm '. Get File test.bpm
        • Method Two: Gunzip-rf ' test.bpm.gz '. Get File test.bpm
        • Note that the difference between the above two methods is the method of extracting the file after the source file will not disappear, but you need to specify the extracted file name; method Two unzip the file, the source file will disappear, but do not need to specify the extracted file name, will be automatically extracted to the same name as the source file
      • Extract the test.bpm.gz file to the specified directory
        • GUNZIP-CRF ' test.bpm.gz ' > '/home/test.bpm '. Get File test.bpm
  • GZIP uses the parameter-D, which is equivalent to Gunzip. This is also the same when extracting a. gz file, using gzip-d to decompress the file. The parameter settings are the same.

Three: Zip and unzip

    • The format for compressing a file using the Zip/unzip command is: Zip parameter [options] ' file or directory '
    • Zip
      • Parameters
        • -C: Results that will be decompressed
        • -L: Displays files contained within the compressed file
        • -N: Do not overwrite the original file when decompressing
        • -V: Show detailed information when performing Yes
        • -C: File names in compressed files are case-sensitive
        • -T: Check that the compressed file is correct
        • -U: Similar to the-f parameter, but other files in the compressed file are extracted to the directory in addition to updating the existing file
      • Chestnuts
        • Compress the test.bpm file to the current directory: Zip-rv ' test.bpm.zip ' test.bpm '
        • Compress the test.bpm file to the/home specified directory: Zip-rv '/home/test.bpm.zip ' test.bpm '
    • Unzip
      • Parameters
        • -d< directory;: Specifies the directory to be stored after extracting the file;
      • Chestnuts
        • Extract the test.bpm.gz file to the current directory: Unzip ' Test.bpm.zip '
        • Compress the test.bpm file to the/home specified directory: Zip '/home/test.bpm.zip '-d '/home '

Linux file compression and decompression usage record

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.