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

How to use the tar Compression Command in Linux

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to use the tar compression command in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.

In the maintenance and management of Linux system, tar command is a frequently used command. The main function of tar command is to package many files into a tar file and compress them, and can keep the permission attributes of files.

Tar command 1, command function

Package the folder, or you can unpack the package into a folder.

2. Option parameters

-c: (create) create a package file

-t: check which files are contained in the contents of the packaged file

-x: unpacking or unzipping, which can be unpacked with-C (uppercase) in a specific directory

-j: compress / decompress with bzip2 support, preferably * .tar.bz2 at this time

-z: compress / decompress with gzip support, preferably * .tar.gz at this time

-v: displays the name of the file being processed during compression / decompression

-f filename:-f followed by the full name of the processed file (path + file name + suffix name)

-C directory: this option is used to extract. To extract in a specific directory, you can use this option.

-p: retains the original permissions and attributes of backup data and is often used to back up (- c) important configuration files

-exclude=FILE: do not package those files during compression

Note that-c,-t,-x cannot appear in a series of instructions at the same time.

3. Case

Case 1: create a demo folder under the / tmp folder, copy the / etc directory to the / tmp/demo directory, and then package it into gz format, requiring the compression details to be displayed.

1) create a demo folder under the / tmp folder and copy the / etc directory to the / tmp/demo directory.

Note: add-r to copy a non-empty directory

2) package and compress the etc folder into gz format, and display the compression details.

Tar-A folder where files are packaged and compressed after being packaged and compressed by czvf

[root@ied01 demo] # tar-czvf myetc.tar.gz etc if the package is compressed into .bz2 format, then the argument to the tar command is-cjvf.

Case 2: first delete the etc directory and extract the myetc.tar.gz to the current directory.

1) delete the etc directory

[root@ied01 demo] # rm-rf etc2) extract the myetc.tar.gz to the current directory

[root@ied01 demo] # tar-xzvf myetc.tar.gz

Case 3: extract the myetc.tar.gz to the specified directory: / home.

[root@ied01 demo] # tar-xzvf myetc.tar.gz-C / home

Case 4: simply unzip a directory in myetc.tar.gz, such as etc/udev.

1) delete the etc directory first

[root@ied01 demo] # rm-rf etc2) extract the etc/udev directory in myetc.tar.gz

[root@ied01 demo] # tar-xzvf myetc.tar.gz etc/udev

Thank you for reading this article carefully. I hope the article "how to use the tar Compression Command in Linux" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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