In Linux, the tar command can save many files together to a separate tape or disk for archiving. The syntax is "tar [option] source file or directory"; it can also restore the required files from the archive file. File, which is the reverse process of packaging, is called unpacking, the syntax is "tar [option] compressed package"; it can also be packaged and compressed at the same time, the syntax is "tar [option] compressed package source file or directory".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Linux tar packaging command detailed explanation
In the Linux system, the most commonly used archiving (packaging) command is tar, which can save many files together into a single Archive to tape or disk. Not only that, this command can also restore the required files from the archive, which is the reverse process of packaging, called unpacking.
Packages archived using the tar command are usually called tar packages (tar package files all end with ".tar").
The tar command performs packaging operations
When the tar command is used for packaging operations, the basic format of the command is:
[root@localhost ~]#tar [选项] 源文件或目录
Copy after login
The commonly used options of this command and their respective meanings are shown in Table 1.
Table 1 tar packaging command common options and their meaning
Options
Meaning
## -c
Package multiple files or directories.
-A
Append the tar file to the archive.
-f package name
Specifies the file name of the package. The extension of the package is used to identify the format for the administrator, so the extension must be specified correctly;
-v
Displays the process of packaging files;
It should be noted that when using the tar command to specify options, you do not need to enter "-" in front of the options. For example, using the "cvf" option has the same effect as "-cvf". Here are a few examples to show you how to use the tar command to package files and directories.
Example 1: Packing files and directories
[root@localhost ~]# tar -cvf anaconda-ks.cfg.tar anaconda-ks.cfg
Copy after login
The option "-cvf" is generally used, remember to use it when packaging Specify the file name after packaging, and use ".tar" as the extension. The same is true for packaging directories:
Example 2: Pack and compress directories
First of all, let’s make it clear that the compression command cannot directly compress directories. You must first use the tar command to package the directory, and then use the gzip command or the bzip2 command to compress the packaged file. For example:
The above is the detailed content of How to use linux tar command. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn