Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the tar command of Linux

Shulou Source: shulou.com Published: 2022-06-01 06:35:08 10月02日 Update

This article will explain in detail how to use the tar command about Linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Tar command

[root@linux ~] # tar [- cxtzjvfpPN] files and directories.

Parameters:

-c: create a parameter instruction for a compressed file (meaning create)

-x: unlock a parameter instruction for a compressed file!

-t: check the files in tarfile!

Pay special attention to that only one c/x/t can exist in the issue of parameters! Cannot exist at the same time! Because it is impossible to compress and decompress at the same time.

-z: does it also have the properties of gzip? That is, is it necessary to use gzip compression?

-j: does it also have the properties of bzip2? That is, is it necessary to use bzip2 compression?

-v: display files in the process of compression! This is commonly used, but is not recommended in the background execution process!

-f: use the file name, please note that you should receive the file name immediately after f! No more parameters!

For example, using "tar-zcvfP tfile sfile" is the wrong way to write it. It should be written as "tar-zcvPf tfile sfile".

-p: use the original properties of the original file (the attributes will not change based on the user)

-P: absolute path can be used to compress!

-N: it is newer than the following date (yyyy/mm/dd) before it is packaged into the new file!

-- exclude FILE: do not package FILE in the process of compression!

Example 1:

Package all the files in the entire / etc directory into / tmp/etc.tar

[root@linux ~] # tar-cvf / tmp/etc.tar / etc

Tags: Files parameters examples properties directories commands at the same time instructions backups articles procedures important representative local more paths different good practical special Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Shulou Technology Shulou Tech Info Huawei