Linux Command file archiving, compression, decompression-tar, gzip, gunzip, bzip2, bunzip2, zip

Source: Internet
Author: User
Tags compress archive

Tar

[Syntax] tar [option] tarfile filename

[Command description]

The file name must be followed by the-f parameter and used as the last parameter;

[Parameter description]

-C. Create a new archive file;

-F specifies the file name;

-R: append an object to an archive object;

-X Extract files from archive files;

-V and-vv display progress information;

-T list the information of the archive file (not extracted );

-C specifies the directory extracted from the file;

-A: Merge multiple tar files;

-- Print the total number of archive bytes after the totals archive is completed;

-- Delete: deletes a specified object from an archive object;

-- Exclude: exclude excludes files of the specified style during archiving;

-J. Use the bunzip2 format to compress the archive file;

-When z generates an archive file, the gzip format is used for compression;

-- Lzma uses lzma format to compress archive files;

-A automatically compresses an archive file based on its extension when generating it;

 

[General usage]

The name is all.tar.

$ Tar-cvf all.tar *. text;

#Add file B .doc

$ Tar-rvf all.tar B .doc;

# List content in an archive object

$ Tar-tvf all.tar;

# Extract all files in the archive file

$ Tar-xvf all.tar;

$ Tar-xvf all.tar-C/opt/app/tool_dir;

# Extract a specified file from an archive file

$ Tar-xvf all.tar file_one file_two

# Merge two tar files

$ Tar-Af file_one.tar file_two.tar

# Deleting a specified object

$ Tar-f all.tar -- delete file_one file_two

# Exclude log files during Archiving

$ Tar-cf all.tar * -- exclude "*. log"

Gzip/gunzip for compression/Decompression

[Syntax]

Gzip [options] file;

Gunzip [options] file;

[Command description]

Gzip can only compress a single file. If multiple files are specified, multiple individual compressed files are generated;

Gzip will delete the source file after generating the compressed file !!!!

After unzipping, gunzip deletes the source file !!!

[Parameter description]

-L, -- list lists the attributes of the compressed file;

-- Fast specifies the minimum compression ratio;

-- Best specifies the maximum compression ratio;

-N specifies the compression ratio (n is a number and 1 <= n <= 9 );

-V displays the progress information;

Bzip2/bunzip2 for compression/Decompression

[Syntax]

Bzip2 file;

Bunzip2 file;

[Command description]

Bzip2 can usually generate files with a higher compression ratio than gzip. By default, bzip2 will delete the source files. You can use the-k parameter to retain the source files;

[Parameter description]

-K: Keep the source file;

-N specifies the compression ratio (n is a number and 1 <= n <= 9 );

Zip/unzip for compression/Decompression

[Syntax] zip [options] file dirs

[Command description]

After zip compression/decompression, the source files are not deleted;

[Parameter description]

-R recursion; used to compress directories;

-L list the compressed file content;

-D. Delete the specified file from the compressed file;

-U: updates the content of the compressed file;

[General usage]

# Compressing files

$ Zip all.zip file;

$ Zip all.zip file_one file_two;

$ Zip-r all.zip dir_name;

# Update a compressed file

$ Zip all.zip-u log. text

# Delete the specified content

$ Zip-d all.zip log. text;

# Decompress the file

$ Unzip all.zip;

# List compressed file content

$ Unzip-l all.zip;

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.