The article directories

  • 1. Compress and decompress commands
    • 1.1 Gzip/gunzip instruction
    • 1.2 zip/unzip instructions
    • 1.3 the tar command

1. Compress and decompress commands

1.1 Gzip/gunzip instruction

  • gzipUsed to compress files,gunzipDecompression
  • The basic grammar

    Gzip file(Function description: Compressed file, can only be compressed as*.gzFile)

    Gunzip file. Gz(Function description: Decompress file command)
  • Examples of application
  1. Case 1:gzipCompression,/homeUnder thehello.txtFile compression
gzip /home/hello.txt
Copy the code

  1. Case 2:gunzipCompression,/homeUnder thehello.txt.gzDecompress the file

1.2 zip/unzip instructions

  • zipUsed to compress files,unzipFor decompression, this is useful in packaged project releases
  • The basic grammar

    Zip [option] xxx.zipWhat to compress (Function Description: Commands to compress files and directories)

    Unzip [option] xxx.zip(Function description: Decompress files)
  • Zip Common options

    -r: Recursive compression, that is, compressed directory
  • Unzip Common option

    -d< directory >: specifies the directory for storing decompressed files
  • Examples of application
  1. Case 1: will/homeUnder all files/folders are compressed intomyhome.zip
Zip -r myhome.zip /homeCopy the code
  1. Case 2: willmyhome.zipunzip/opt/tmpdirectory
mkdir /opt/tmp
unzip -d /opt/tmp /home/myhome.zip
Copy the code

1.3 the tar command

  • tarThe directive is the package directive, and the last packaged file is.tar.gzThe file.
  • The basic grammar

    Tar [option] xxx.tar. gz Package content(Function description: Package a directory in compressed format. Tar.gz)√ Option Description
  • Option to show

  • Examples of application
  1. Case 1: Compressing multiple files will/home/pig.txtand/home/cat.txtCompressed intopc.tar.gz
tar -zcvf pc.tar.gz /home/pig.txt /home/cat.txt
Copy the code
  1. Case 2: Compress the /home folder into myhome.tar.gztar-zcvf myhome.tar.gz /home/
tar -zcvf myhome.tar.gz /home/
Copy the code
  1. Case 3: Decompress pc.tar.gz to the current directory, tar -zxvf pc.tar.gz
tar -zxvf pc.tar.gz
Copy the code
  1. Case 4: willmyhome.tar.gzunzip/opt/tmp2directory

    (1) mkdir /opt/tmp2

    (2) tar -zxvf /home/myhome.tar.gz -C /opt/tmp2