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

Introduction to Linux Archiving and Compression Command

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

Share

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

Today, I will bring you an article introducing Linux archiving and compression commands. Xiao Bian thinks it is quite practical, so share it for everyone to make a reference. Let's follow the editor and have a look.

Archive, also known as packaging, refers to a collection of files or directories that are stored in a file. The archive file is not compressed, so it takes up the sum of all the files and directories in it.

Compression refers to the use of algorithms to process files, which has achieved the purpose of retaining maximum file information and reducing file size. The basic principle is to create a dictionary file of the same bytes by looking for duplicate bytes in the file and using a code to represent them. For example, if "hello, world" appears in more than one place in the compressed file, then when the file is compressed, this word will be represented by a code and written into the dictionary file, so that the file size can be reduced.

Under Linux, there are two commonly used archive commands, tar and dd (tar is more widely used); there are many commonly used compression commands, such as gzip, zip, bzip2, etc. The detailed usage of these commands will be described in subsequent documents.

tar command to do packaging operations

When the tar command is used for packaging operations, its basic format is:

[root@localhost ~]#tar [options] source file or directory

Common options for this command and their respective meanings are shown in Table 1.

Table 1 Common options and meanings of tar packaging command Option meanings-c Packaging multiple files or directories. - A appends tar file to archive file. - f Package Name Specifies the file name of the package. Package extensions are used to identify the format to the administrator, so be sure to specify the extension correctly;-v shows the packaging process;

Note that you can specify options using tar without entering "-" in front of the options. For example, using the "cvf" option works the same as "-cvf."

tar command to unpack

When the tar command is used to unpack a tar package, the basic format of the command is as follows:

[root@localhost ~]#tar [options] compressed package

When used for unpacking, common options and meanings are shown in Table 2.

Table 2 Common options and meanings of tar unpacking Option meanings-x Unpacking tar packages. - f Specifies the package name of the tar package to extract. - tLook only at what files or directories are in the tar package, do not unpack it. - C Directory specifies the unpacking location. - v Shows the unpacking process.

tar command to pack compression (decompression unpacking) operation

When the tar command is used to pack and compress at the same time, its basic format is as follows:

[root@localhost ~]#tar [options] Compressed package source files or directories

There are two commonly used options here, namely:

-z: compression and decompression of the ".tar.gz" format;

-j: Compresses and decompresses the ".tar.bz2" format.

zip command

Similar to winzip in Windows, its basic format is as follows:

[root@localhost ~]#zip [options] zip package name source file or source directory list

Note that the zip compression command needs to manually specify the compressed package name after compression. Note that the extension is clearly written so that it can be used when decompressing.

Several options commonly used in this command and their respective meanings are shown in Table 1.

Table 1 Common options and meanings of zip command Option meanings-r Recursively compress directories, and compress all files and subdirectories under the specified directory. - m After compressing the file, delete the original file, which is equivalent to moving the file into the compressed file. - v Displays detailed compression process information. - q Does not show command execution when compressed. - Compression level Compression level is a number from 1 to 9,-1 means faster compression,-9 means better compression. - u Update compressed files, i.e. add new files to compressed files.

unzip command

The unzip command can view and unzip files. The basic format of this command is as follows:

[root@localhost ~]# unzip [options] zip package name

Common options for this command and their meanings are shown in Table 1.

Table 1 Common options and meanings of unzip command Option meanings-d directory names Extract compressed files to specified directories. - n Decompressing does not overwrite existing files. - o Overwrite existing files when extracting without user confirmation. - v View the details of the compressed file, including the file size, file name and compression ratio contained in the compressed file, but do not decompress the operation. - t Tests compressed files for corruption, but does not decompress. - The x file list extracts files, but does not contain the files specified in the file list.

gzip command

gzip is a command often used in Linux systems to compress and decompress files. The new file compressed by this command is usually labeled with the extension ".gz."

Again, the gzip command can only be used to compress files, not directories, and even if a directory is specified, it can only compress all files in the directory.

The basic format of the gzip command is as follows:

[root@localhost ~]# gzip [options] source file

The source file in the command refers to an ordinary file when compression is performed, and refers to a compressed file when decompression is performed. Common options and meanings of this command are shown in Table 1.

Table 1 Common options and meanings of gzip command Option meanings-c Output compressed data to standard output and keep source files. - d Decompresses compressed files. - r Recursively compresses all files in the specified directory and subdirectories. - v For each compressed and decompressed file, display the file name and compression ratio. - 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.

- Numbers are used to specify compression levels,-1 has the lowest compression level and the worst compression ratio;-9 has the highest compression ratio. The default compression ratio is-6.

gunzip command

Gunzip is a widely used decompression command for extracting files compressed by gzip (extension.gz).

For extracting files compressed by gzip, you can also use gzip itself, the gzip -d archive.

The basic format of the gunzip command is:

[root@localhost ~]# gunzip [options] file

Common options and meanings of this command are shown in Table 1.

Table 1 Common options and meanings of gunzip command Option meanings-r Recursive processing, decompression of all files in the specified directory and subdirectories. - c Output the decompressed file to a standard output device. - f Force unzipped files regardless of whether they already exist, etc. - l List compressed file contents. - v Displays command execution. - tTests whether the compressed file is OK, but does not decompress it.

bzip2 Command

The bzip2 command is similar to the gzip command in that it can only compress (or decompress) files, and for directories, it can only compress (or decompress) all files in the directory and its subdirectories. When the compression task is completed, a compressed package with the suffix ".bz2" is generated.

The ".bz2" format is another compression format for Linux. Theoretically, the ".bz2" format has a more advanced algorithm and better compression ratio, while the ".gz" format is relatively faster.

The basic format of the bzip2 command is as follows:

[root@localhost ~]# bzip2 [options] source file

Source file refers to the file to be compressed or decompressed. The common options of this command and their respective meanings are shown in Table 1.

Table 1 Common Options and Meanings of bzip2 Command Option Meaning-d Perform decompression. In this case, the source file after this option shall be a compressed package file marked with.bz2 suffix. - kbzip2 deletes the original file after the compression or decompression task is complete, use this option to keep the original file. - fbzip2 When compressing or decompressing, if the output file has the same name as the existing file, the existing file will not be overwritten by default. If this option is used, the existing file will be forcibly overwritten. - tTests the integrity of the compressed package file. - v Displays details when compressing or decompressing files. - This parameter has the same effect as the gzip command. It is used to specify the compression level.-1 has the lowest compression level and the worst compression ratio;-9 has the highest compression ratio.

Note that gzip simply doesn't pack directories, but if you use the "-r" option, you can compress each file in a directory separately; bzip2 doesn't support compressing directories at all, and there is no "-r" option.

bunzip2 command

To extract a compressed package file in the format ".bz2," use bunzip2 instead of "bzip2 -d compressed package name."

Bunzip2 is used in much the same way as gunzip. Bunzip2 can only be used to extract files. Even if you extract a directory, you extract all files in that directory and its subdirectories.

The basic format of the bunzip2 command is:

[root@localhost ~]# bunzip2 [options] source file

Common options for this command and their meanings are shown in Table 1.

Table 1 bunzip2 command options and their meanings Option meanings-k After decompression, the original compressed file will be deleted by default. This parameter is required to preserve compressed files. - f When extracting, if the output file has the same name as the existing file, the existing file will not be overwritten by default. To override, use this option. - v Displays command execution. - L Lists the contents of compressed files.

The above is the Linux archive and compression command details, after reading whether there is any harvest? If you want to know more about it, welcome to pay attention to industry information!

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