In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the Linux tar packaging commands", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what Linux tar packaging commands are available.
Preface
In Linux systems, the commonly used packaging command is tar, which can save many files together to a separate tape or disk for archiving. Not only that, this command can also restore the required files from the archive file, which is the reverse process of packaging, called unpacking.
Packages archived (packaged) using tar become tar packages, and the file name ends with .tar.
Tar Packaging Operation Command
Basic format:
[root@localhost ~] # tar [option] Source file or directory
The options commonly used for this command and their respective meanings are shown in the following table. :
Option meaning-c packages multiple files or directories. -An append the tar file to the archive file. -f package name specifies the file name of the package. The package extension is used to identify the format for the administrator, so be sure to specify the extension correctly;-v shows the packaging file process
Note: you can specify an option without entering "-" before the option using the tar command. For example, using the "cvf" option has the same effect as "- cvf".
Examples of packaging are as follows:
[root@localhost ~] # tar-cvf anaconda-ks.cfg.tar anaconda-ks.cfg
# package anacondehks.cfg as an anacondehks.cfg.tar file
The option "- cvf" is generally an idiom, so remember that you need to specify the filename after packaging and use ".tar" as the extension. Package catalogs also need to be the same:
[root@localhost] # ll-d test/
Drwxr-xr-x 2 root root 4096 June 17 21:09 test/
# test is our previous test directory
[root@localhost ~] # tar-cvf test.tar test/
Test/
Test/test3
Test/test2
Test/test1
# package the directory as a test.tar file
The tar command can also package multiple files or directories, as long as they are separated by spaces. For example:
[root@localhost ~] # tar-cvf ana.tar anaconda-ks.cfg / tmp/
# package the anaconda-ks.cfg file and / tmp directory into an ana.tar package
When you package and compress a directory, the compress command cannot compress the directory directly. You must package the directory with the tar command before you can compress the packaged file with the gzip command or the bzip2 command. Examples are as follows:
[root@localhost] # ll-d test test.tar
Drwxr-xr-x 2 root root 4096 June 17 21:09 test
-rw-r--r-- 1 root root 10240 June 18 01:06 test.tar
# We have packaged the test directory into a test.tar file before
[root@localhost ~] # gzip test.tar
[root@localhost ~] # ll test.tar.gz
-rw-r--r-- 1 root root 18 June 01:06 test.tar.gz
# gzip command will compress test.tar into test.tar.gztar unpacking command operation
Basic format:
[root@localhost ~] # tar [option] package
When unpacking, the common options and meanings are shown in the following table:
Option meaning-x unpack the tar package. -f specifies the package name of the tar package to be extracted. -t only check the files or directories in the tar package, and do not unpack the tar package. The-C directory specifies the unpacking location-v shows the specific process of unpacking.
Examples are as follows:
[root@localhost] # tar-xvf anaconda-ks.cfg. Tar
# unpack the package to the current directory
If you use the "- xvf" option, the files in the package will be extracted to the current directory. If you want to specify the decompression location, you need to use the-C (uppercase) option. For example:
[root@localhost] # tar-xvf test.tar-C / tmp
# unpack the package test.tar to the / tmp/ directory
If you only want to see which files are in the package, you can replace the unpack option "- x" with the test option "- t". For example:
[root@localhost ~] # tar-tvf test.tar
Drwxr-xr-x root/root 0 2016-06-17 21:09 test/
-rw-r-r- root/root 0 2016-06-17 17:51 test/test3
-rw-r-r- root/root 0 2016-06-17 17:51 test/test2
-rw-r-r- root/root 0 2016-06-17 17:51 test/test1
# will display the details of the files in the test.tar package in a long format tar command to do packaging and compression (decompression and unpacking) operation
In fact, the tar command can be packaged and compressed at the same time, separately, in order to let everyone understand the difference between packaging and compression in Linux.
The basic format is as follows:
[root@localhost ~] # tar [option] compressed package source file or directory
There are two options commonly used here, namely:
1.-z: compression and decompression ".tar.gz" format
2.-j: compress and decompress the ".tar.bz2" format.
The format of compressing and decompressing ".tar.gz" is as follows:
[root@localhost ~] # tar-zcvf tmp.tar.gz / tmp/
# package / temp/ directory directly to ".tar.gz" format, identify the format by "- z", and "- cvf" is consistent with the packaging option
Unzipping only adds a "- z" option to the unpacking option "- xvf".
[root@localhost ~] # tar-zxvf tmp.tar.gz
# decompress and unpack ".tar.gz" format
The above option "- C" is used to specify the decompression location, and "- t" is used to view the contents of the package, which also applies here.
Compress and extract the ".tar.bz2" format.
The only difference between the ".tar.gz" format and the ".tar.gz" format is that the "- zcvf" option is replaced with "- jcvf", as follows:
[root@localhost ~] # tar-jcvf tmp.tar.bz2 / tmp/# is packaged and compressed to ".tar.bz2" format. Note that the file name of the compressed package [root@localhost ~] # tar-jxvf tmp.tar.bz2# decompresses and unpacks ".tar.bz2" format.
Note: compress the file directly into ".tar.gz" and ".tar.bz2" format, which is the most commonly used compression method in Linux. This is the compression and decompression method that we must master.
At this point, I believe you have a deeper understanding of "what are the Linux tar packaging commands"? you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.