Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of all kinds of compressed packages in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "summary of all kinds of compressed packages in linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "summary of all kinds of compressed packages in linux".

This is the method available on the Internet:

.tar.gz

Decompress: tar zxvf FileName.tar.gz

Compression: tar zcvf FileName.tar.gz DirName1 DirName2

This paper roughly summarizes the compression and decompression methods of various formats under linux. But some of the methods I did not use, it is not complete, I hope you can help me to supplement, I will modify and improve at any time, thank you!

.tar

Unpack: tar xvf FileName.tar

Packaging: tar cvf FileName.tar DirName

(note: tar is packaging, not compression! )

-

.gz

Decompress 1:gunzip FileName.gz

Decompress 2:gzip-d FileName.gz

Compression: gzip FileName

.tar.gz and .tgz

Decompress: tar zxvf FileName.tar.gz

Compression: tar zcvf FileName.tar.gz DirName

-

.bz2

Decompress 1:bzip2-d FileName.bz2

Decompress 2:bunzip2 FileName.bz2

Compression: bzip2-z FileName

.tar.bz2

Decompress: tar jxvf FileName.tar.bz2

Compression: tar jcvf FileName.tar.bz2 DirName

-

.bz

Decompress 1:bzip2-d FileName.bz

Decompress 2:bunzip2 FileName.bz

Compression: unknown

.tar.bz

Decompress: tar jxvf FileName.tar.bz

Compression: unknown

-

.Z

Decompress: uncompress FileName.Z

Compression: compress FileName

.tar.Z

Decompress: tar Zxvf FileName.tar.Z

Compression: tar Zcvf FileName.tar.Z DirName

-

.zip

Decompress: unzip FileName.zip

Compression: zip FileName.zip DirName

-

.rar

Decompress: rar x FileName.rar

Compression: rar a FileName.rar DirName

Rar can be downloaded at http://www.rarsoft.com/download.htm!

After decompressing, copy rar_static to the / usr/bin directory (other directories specified by the $PATH environment variable are also acceptable):

[root@www2 tmp] # cp rar_static / usr/bin/rar

-

.lha

Decompress: lha-e FileName.lha

Compression: lha-a FileName.lha FileName

Lha can be downloaded at http://www.infor.kanazawa-it.ac.jp/~ishii/lhaunix/!

> after decompression, copy lha to the / usr/bin directory (other directories specified by the $PATH environment variable are also acceptable):

[root@www2 tmp] # cp lha / usr/bin/

-

.rpm

Unpack: rpm2cpio FileName.rpm | cpio-div

-

.deb

Unpack: ar p FileName.deb data.tar.gz | tar zxf-

-

.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm

.deb .slp .arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx

.zoo .cab .kar .cpt .pit .sit .sea

Decompress: sEx x FileName.*

Compression: sEx a FileName.* FileName

SEx only calls the relevant procedures, there is no compression, decompression function, please pay attention!

SEx can be downloaded at http://sourceforge.net/projects/sex!

After decompressing, copy sEx to the / usr/bin directory (other directories specified by the $PATH environment variable are also acceptable):

[root@www2 tmp] # cp sEx / usr/bin/

Reference: guide to the Linux file compression tool

In fact, help is the best way, generally each command can use the "--help" parameter to get the common usage! )

Users often need to back up the data in the computer system, and the backup files are often compressed in order to save storage space. The commands for backup and compression are described below.

Tar command

Tar can create archives for files and directories. With tar, users can create a file (backup file) for a particular file, change the file in the file, or add new documents to the file. Tar was originally used to create files on tape, but now users can create files on any device, such as floppy disks. With the tar command, you can package a large pile of files and directories into one file, which is useful for backing up files or combining several files into one file for network transfer. Tar on Linux is the GNU version.

Syntax: tar [primary option + secondary option] file or directory

When using this command, the primary option is required, which tells tar what to do, and the secondary option is secondary and optional.

Main options:

C create a new archive file. Select this option if the user wants to back up a directory or some files.

R append the file to be archived to the end of the file. For example, if the user has already backed up the file and found that there is another directory or some files that have forgotten to back up, you can use this option to append the forgotten directory or file to the backup file.

T list the contents of the archive file to see which files have been backed up.

U update the file. That is, replace the original backup file with the new file, and if the file to be updated is not found in the backup file, append it to the end of the backup file.

X release the file from the archive file.

Secondary options:

B this option is set for the tape drive. Followed by a number to indicate the size of the block, the system default value is 20 (20,512 bytes).

F use archives or devices, this option is usually required.

K saves files that already exist. For example, we restore a file, in the restore process, encounter the same file, will not be overwritten.

M when restoring files, set the modification time of all files to now.

M creates multi-volume archives for storage on several disks.

V report the file information processed by tar in detail. Without this option, tar does not report file information.

W confirmation is required for each step.

Z use gzip to compress / unzip files, add this option to compress files, but be sure to use this option to unzip files when restoring.

Example 1: back up all the subdirectories in the / home directory, and the backup file name is usr.tar.

$tar cvf usr.tar / home

Example 2: back up all the files in the / home directory, including its subdirectories, and compress them. The backup file is called usr.tar.gz.

$tar czvf usr.tar.gz / home

Example 3: restore and decompress the backup file usr.tar.gz.

$tar xzvf usr.tar.gz

Example 4: view the contents of the usr.tar backup file and display it on the monitor in a split-screen manner.

$tar tvf usr.tar | more

To back up files to a specific device, simply use the device name as the backup file name.

Example 5: the user creates a backup file on the floppy disk of the / dev/fd0 device and copies all the files in the / home directory to the backup file.

$tar cf / dev/fd0 / home

To recover files from the device disk, use the xf option:

$tar xf / dev/fd0

If the size of the file backed up by the user exceeds the storage space available to the device, such as a floppy disk, you can create a multi-volume tar backup file. The M option instructs the tar command to prompt you to use a new storage device, and when you use the M option to archive to a floppy drive, the tar command will remind you to insert a new floppy disk when a floppy disk is full. This allows you to save tar files to several disks.

$tar cMf / dev/fd0 / home

To restore the files on several disks, simply put the first one in the floppy drive and enter the tar command with the x and M options. You will be reminded to put another floppy disk if necessary.

$tar xMf / dev/fd0

Gzip command

Reducing file size has two obvious benefits: one is that you can reduce storage space, and the other is that you can reduce the transfer time when transferring files over the network. Gzip is a command that is often used in Linux system to compress and decompress files, which is convenient and easy to use.

Syntax: gzip [option] compressed (unzipped) file name

The meaning of each option:

-c writes the output to standard output and keeps the original file.

-d decompress the compressed file.

-l for each compressed file, the following fields are displayed:

The size of the compressed file

The size of the uncompressed file

Compression ratio

The name of the uncompressed file

-r recursively finds the specified directory and compresses or decompresses all files in it.

-t test to check whether the compressed file is complete.

-v displays the file name and compression ratio for each compressed and unzipped file.

-num adjusts the speed of compression with the specified numeric num,-1 or-fast represents the fastest compression method (low compression ratio), and-9 or-- best represents the slowest compression method (high compression ratio). The system default is 6.

Suppose there are files mm.txt, sort.txt, xx.com in a directory / home.

Example 1: compress each file in the / home directory into a .gz file.

$cd / home

$gzip *

$ls

M.txt.gz sort.txt.gz xx.com.gz

Example 2: decompress each compressed file in example 1 and list the detailed information.

$gzip-dv *

Mm.txt.gz 43.1%-replaced with mm.txt

Sort.txt.gz 43.1%-replaced with sort.txt

Xx.com.gz 43.1%-replaced with xx.com

$ls

Mm.txt sort.txt xx.com

Example 3: the information of each compressed file in example 1 is displayed in detail and is not decompressed.

$gzip-l *

Compressed uncompr. Ratio uncompressed_name

277 445 43.1% mm.txt

278 445 43.1% sort.txt

277 445 43.1% xx.com

$ls

Mm.txt.gz sort.txt.gz xx.com.gz

Example 4: compress a tar backup file, such as usr.tar, with a .tar.gz extension

$gzip usr.tar

$ls

Usr.tar.gz

Unzip command

How to expand the files compressed by winzip under MS Windows under the Linux system? You can use the unzip command, which is used to unzip a compressed file with a .zip extension.

Syntax: unzip [option] compressed file name. Zip

The meaning of each option is:

The-x file list unzips the file, but does not include the specified file file.

-v View the directory of compressed files, but do not unzip them.

-t test the file for damage, but do not unzip it.

The-d directory unloads the compressed files to the specified directory.

-z displays only comments for compressed files.

-n does not overwrite existing files.

-o overwrite existing files and do not require user confirmation.

-j does not reconstruct the directory structure of the document and unzips all files to the same directory.

Example 1: unzip the compressed file text.zip in the current directory.

$unzip text.zip

Example 2: extract the compressed file text.zip under the specified directory / tmp. If the same file already exists, the unzip command is required not to overwrite the original file.

$unzip-n text.zip-d / tmp

Example 3: view the compressed file directory, but do not extract it.

$unzip-v text.zip

Zgrep command

The function of this command is to find a matching regular expression in the compressed file, using the same as the grep command, except that the object of the operation is the compressed file. If the user wants to see if there is a sentence in a compressed file, he can use the zgrep command.

Thank you for your reading, the above is the content of "summary of all kinds of compressed packages in linux". After the study of this article, I believe you have a deeper understanding of the problem of summarizing all kinds of compressed packages in linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report