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

What is the command to compress files in Linux

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

Share

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

What this article shares to you is about what the compressed file command in Linux is, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Don't say much, follow the editor to have a look.

Compression is a good choice when the file is too large, and there are many ways to compress it in Linux, the most commonly used is the tar command.

Description of file suffix for commonly used compressed package file format *. Zipzip program packaged compressed file * .rarrar program compressed file * .7z7zip program compressed file * .tartar program packaged, uncompressed file * .gzgzip program (GNU zip) compressed file * .xzxz program compressed file * .bz2bzip2 program compressed file * .tar.gztar package, gzip program compressed file * .tar.xztar package Xz program compressed file * tar.bz2tar package, bzip2 program compressed file * .tar.7ztar package, 7z program compressed file [zip package compression and decompression] 1. File packaging and compression command format: file name created by zip [option] .zip absolute path to package compression

Common options:

-r indicates that the recursive package contains all the contents of the subdirectory (selected when packing the directory)-Q is expressed in quiet mode, that is, the information is not output to the screen-o output file, the compression efficiency needs to be set immediately after the package output file name-[1-9], 1 indicates the fastest compression but large size, 9 indicates the smallest size but takes the longest-e to set the password, when you create an encrypted compression package-l compression file Replace LF characters with LF+CR characters-when ll compressed files, replace LF+cp characters with LF characters

Note: because Windows system and Linux system have compatibility problems in text file format, such as newline character (invisible character), CR+LF in Windows (Carriage-Return+Line-Feed: enter plus newline) and LF (newline in Linux), you can use the option-l or-ll to convert when compressing the file.

two。 Unzip use the unzip command to extract the .zip package that is compressed by the zip command.

Command format: unzip [option] compressed package name .zip

Common options:

-Q is expressed in quiet mode, that is, information is not output to the screen-l displays the files contained in the compressed file, but does not extract-d specifies the directory to be stored after the file is unzipped (if the specified directory does not exist, the directory will be created automatically)

[tar Packaging tool] tar is a packaging tool, but it also supports 7z, gzip, xz, bzip2 and other tools. These compression tools themselves can only compress files or directories (files in separate compressed directories), but not files.

The decompression and compression of tar are the same command, but the options are different.

1. Basic operation 1) create a tar package

Command format: file name created by tar-c-f. Absolute path to be packaged by tar

Note:-c means to create a tar package file, and-f is used to specify the file name to be created, and the file name must be immediately after-f

Common options for packaging:

-v visually outputs the packaged file, automatically removing the / that represents the absolute path

-P retains the absolute path symbol.

2) unpack a file to an existing directory in the specified path

Command format: tar-x-f file name to extract. Tar-C existing directory

Note:-x means to extract a tar package file,-f is used to specify the file name to be extracted, and-C is used to specify a specific decompression directory.

3) only view but not decompress

Command format: tar-t-f file name to view .tar

4) preserve file attributes and follow links (symbolic links or soft links)

Sometimes you use tar to back up files, and you want to retain the properties of the file and the source file that the backup link points to when you restore it on another host.

The following two options are available:

-p: preserve the attributes of the file

-h: backup the source file that the link points to instead of the link itself

two。 To create files in different compressed formats, use other compression tools to create or extract the corresponding files, simply add an option to the tar command.

The compressed file format option * .tar.gz-z*.tar.xz-J*tar.bz2-j is shown in the following figure, taking * .tar.gz as an example:

File packing and compression

File decompression

The powerful tar command is the preferred command by many candidates. If you don't know anything, you can leave a message in the comment area below. I will answer it for you in time.

These are the commands for compressing files in Linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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

Development

Wechat

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

12
Report