How to use tar command in linux system
How can the tar command be used in a linux system? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
Tar syntax:
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. It's the equivalent of packing.
X release the file from the archive file. It's the equivalent of unpacking.
T list the contents of the archive file to see which files have been backed up.
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.
Secondary options:
-z: does it also have the properties of gzip? That is, does it need to be compressed or decompressed with gzip? The general format is xx.tar.gz or xx. Tgz
-j: does it also have the properties of bzip2? That is, does it need to be compressed or decompressed with bzip2? The general format is xx.tar.bz2
-v: display files in the process of compression! This is commonly used.
-f: use the file name, please note that you should receive the file name immediately after f! Don't add any other parameters!
-p: use the original properties of the original file (the attributes will not change based on the user)
-- exclude FILE: do not package FILE in the process of compression!
Example:
Example 1: package all the files in the entire / etc directory into / tmp/etc.tar
Copy the code
The code is as follows:
[root@linux ~] # tar-cvf / tmp/etc.tar / etc