File packaging and compression under Linux

Source: Internet
Author: User

1. Packaging and compressing files
Current gzip and bzip2 are commonly used under Linux to compress files, tar package files. Common extensions: *.gz gzip Compressed files *.bz2 bzip2 Compressed files *.tar tar packaged files, no compressed *.tar.gz tar package files, gzip compressed *.tar.bz2 tar package files, bzip2 compressed
2. Gzip compression
Gzip is the most widely used compression command. Used instead of compress compression.
$ gzip-hgzip 1.3.3 (2002-03-08) usage:gzip [-cdfhllnnrtvv19] [-s suffix] [file ...] Common Parameters-C: Compressed data output to the screen, can redirect processing-D: Decompression-T: Verify the consistency of the compressed file, see if the file is error-V: Display compression details, compression ratio, etc.-#: number, compression level, 1-9,9 compression rate, default 6
Compress files
$ gzip-v testtest:   53.1%--Replaced with test.gz
Compression will erase local files, new test.gz files do not delete files using redirection
$ gzip-c Test > test.gz
View compressed file contents, without decompression, using the Zcat command

3. bzip2
BZIP2 is used instead of gzip compression, which is higher than gzip compression ratio and uses almost the same parameters as gzip.
$ BZIP2-HBZIP2, a block-sorting file compressor.  Version 1.0.2, 30-dec-2001.   USAGE:BZIP2 [flags and input files in any order] common parameter-C: Compressed data output to the screen, can be redirected processing-D: Decompression-K: Keep the original file-Z: Compression-T: Verify the consistency of the compressed file, see if the file is wrong Error-V: Show the details of compression, compression ratio, etc.-#: number, compression level, 1-9,9 compression rate is the highest, default 6
Use
#压缩test文件, generate test.bz2$ bzip2-z test# retain original file, compress generate test.bz2$ bzip2-k test# extract file $ bzip2-d test.bz2
View compressed file contents, using Bzcat

3. Packaging: Tar
Tar is a packaged command that packages multiple files into a single file. Also contains compression parameters.
$ tar--helpgnu ' tar ' saves many files together into a single tape or disk archive, Andcan restore individual files from T He archive. Usage:tar [OPTION] ... [FILE] ... Examples:  tar-cf archive.tar foo bar  # Create Archive.tar from Files foo and bar.  TAR-TVF Archive.tar         # List All files in Archive.tar verbosely.  TAR-XF Archive.tar          # Extract all files from Archive.tar. #参数-C New Compressed file-T list compressed file list-X Extract file   -c,-t,-x cannot appear at the same time-j through BZIP2 To compress or decompress, the file name is best. *.tar.bz2-z by gzip compression or decompression, the file name is best for *.tar.gz-v show the details being processed after-F and the file name to be processed-C decompression, followed by the extracted directory name-p retain the original permissions of the file-P-reserved Absolute path--exclude= File exclusions
Basic usage of tar
#创建bzip2压缩文件 $ tar-jcv-f test.tar.bz2 test/test/test/1test/10# Create gzip compressed file $ tar-zcv-f test.tar.gz testtest/test/1test/ 10# View Files $ lldrwxrwxr-x  2 work work     4096 Jul 19:12 test-rw-rw-r--1 Work work    61897 Jul 19:13 Test.tar . bz2# View File List $ tar-jtv-f test.tar.bz2 tar:record size = 8 blocksdrwxrwxr-x work/work         0 2014-07-19 19:12:40 tes t/-rw-rw-r--work/work      6353 2014-07-19 19:12:40 test/1-rw-rw-r--work/work      6343 2014-07-19 19:12:40 test/10# Unzip to the current directory $ tar-jxv-f test.tar.bz2 test/test/1test/10# extract to the specified directory test2$ mkdir test2$ tar-jxv-f test.tar.bz2-c test2  
Do not include a file when packaging
#创建压缩文件, does not contain a file test/10$ tar-zcv-f test.tar.gz  --EXCLUDE=TEST/10 TEST/*TEST/1
Back up files that are newer than at some point
$ tar-zcv-f etc.tar.gz--newer-mtime= "2013/10/31"/etc/*/etc/xinetd.d/tar:/etc/yp.conf:file is unchanged; Not Dumped#not DUMPD indicates that there is no backup

Address: http://blog.csdn.net/yonggang7/article/details/37963793

File packaging and compression under Linux

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.