Linux basic commands (3) file backup and compression commands

Source: Internet
Author: User
Tags bz2 zip extension

file backup and compression commands

In Linux, the commonly used file compression tools are gzip, bzip2, zip. BZIP2 is the ideal compression tool that provides maximum compression. Zip compatibility is good and Windows supports it.

Command Function
Bzip2/bunzip2 Compression/Decompression tool with extension bz2
Gzip/gunzip Zip/Unzip tool with extension GZ
Zip/unzip Compression/Decompression tool with zip extension
Tar Create Backup and Archive
3.1 bzip2 Command

To compress a file using bzip2, enter the command at the shell prompt:

bzip2 filename

The file is compressed and saved as filename.bz2.

To extract a file, enter the command:

BUNZIP2 filename.bz2

FILENAME.BZ2 will be deleted and replaced with filename.

bzip2 filename.bz2 file1 file2 file3/usr/work/school

The above command compresses the contents of the File1, File2, File3, and/usr/work/school directories and puts them in filename.bz2.

3.2 gzip Command

To compress a file using gzip, enter the command:

gzip filename

The file is compressed and saved as filename.gz.

To extract a file, enter the command:

Gunzip filename.gz

Filename.gz will be deleted and replaced with filename.

Gzip-r filename.gz file1 file2 file3/usr/work/school

The above command compresses the contents of the File1, File2, File3, and/usr/work/school directories and puts them in filename.gz.

3.3 Zip command

The zip command is used in conjunction with GZIP.

3.4 tar Command

The TAR command was originally used for tape backup, but because of the increasing capacity of the hard disk, the main use of this command now is to back up all the files. Tar this command packs a large number of files and directories into a file.

option function
-c Create a new archive
-f when with-C selection Item is used together, the tar file created uses the file name specified by this option, and when used with the-X option, the archive
-t
-v
-x Extract files from archive
-z use gzip to compress tar files
-j use bzip2 to compress tar files

To create a tar file, enter the command:

TAR–CVF Filename.tar Directory/file/home/mine

The above command puts Directory/file,/home/mine into the archive.

To list the contents of a tar file, enter the command:

TAR–TVF Filename.tar

To extract the tar file command, enter the command:

TAR–XVF Filename.tar

This command does not delete the tar file, but it copies the contents of the archive to the current working directory and preserves any directory structure used by the archive file.

Keep in mind that tar does not compress files by default. To create a file that uses tar and bzip2 to archive compressed files, use the-J option:

TAR–CJVF filename.tbz File

If you use the BUNZIP2 command to extract the Filename.tbz file, the FILENAME.TBZ is deleted and replaced with Filename.tar.

To extend and de-archive the bZIP tar file, enter the command:

TAR–XJVF FILENAME.TBZ

To create a file that is archived and compressed in tar and gzip, use the-Z option:

TAR–CZVF filename.tgz File

If you use the Gunzip command to extract the Filename.tgz file, the filename.tgz is deleted and replaced with Filename.tar.

Linux basic commands (3) file backup and compression commands

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.