In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the tar command in the linux system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Access to the server through SSH, it is inevitable to use compression, decompression, packaging, unpacking and so on, at this time the tar command is an essential and powerful tool. The most popular tar in linux is the sparrow, which is small, well-equipped and powerful.
Tar
The most commonly used packaging command is tar. Packages typed using tar programs are often called tar packages, and commands for tar package files usually end with .tar. After you generate the tar package, you can use other programs to compress it, so let's first talk about the basic usage of the tar command.
There are many options for the tar command (you can see them with man tar), but there are only a few commonly used options. Here's an example:
# tar-cf all.tar * .jpg
This command is to type all .jpg files into a package called all.tar. -c means to generate a new package, and-f specifies the file name of the package.
# tar-rf all.tar * .gif
This command adds all .gif files to the all.tar package, and-r means to add files.
# tar-uf all.tar logo.gif
This command updates the logo.gif file in the original tar package all.tar, and-u means to update the file.
# tar-tf all.tar
This command lists all the files in the all.tar package, and-t means to list files.
# tar-xf all.tar
This command unlocks all the files in the all.tar package, and-x means to unlock it.
These are the most basic uses of tar. In order to make it convenient for users to compress or extract files while packing and unpacking, tar provides a special function. This means that tar can call other compression programs, such as gzip, bzip2, etc., while packaging or unpacking.
1) call tar
Gzip is a compression program developed by GNU organization, and the file at the end of .gz is the result of gzip compression. The decompression program as opposed to gzip is gunzip. The parameter-z is used in tar to call gzip. Here is an example:
# tar-czf all.tar.gz * .jpg
This command is to package all .jpg files into a tar package and compress it with gzip to generate a gzip compressed package named all.tar.gz.
# tar-xzf all.tar.gz
This command is to unlock the package generated above.
2) tar calls bzip2
Bzip2 is a more powerful compression program, and the file at the end of .bz2 is the result of bzip2 compression.
The decompression program as opposed to bzip2 is bunzip2. The parameter-j is used in tar to call gzip. Here is an example:
# tar-cjf all.tar.bz2 * .jpg
This command forms all .jpg files into a tar package and compresses it with bzip2 to generate a bzip2-compressed package named all.tar.bz2
# tar-xjf all.tar.bz2
This command is to unlock the package generated above.
3) tar calls compress
Compress is also a compression program, but it seems that not as many people use compress as gzip and bzip2. The file at the end of .Z is the result of bzip2 compression. The decompression program as opposed to compress is uncompress. The parameter-Z is used in tar to call compress. Here is an example:
# tar-cZf all.tar.Z * .jpg
This command is to package all .jpg files into a tar package and compress it with compress to generate a uncompress compressed package named all.tar.Z.
# tar-xZf all.tar.Z
This command is to unlock the package generated above.
With the above knowledge, you should be able to unlock a variety of compressed files. Here is a summary of the compressed files of the tar series:
1) for .tar ending files tar-xf all.tar2) for .gz ending files gzip-d all.gzgunzip all.gz3) for .tgz or .tar.gz ending files tar-xzf all.tar.gztar-xzf all.tgz4) for .bz2 ending files bzip2-d all.bz2bunzip2 all.bz25) for tar.bz2 ending files tar-xjf all.tar.bz26) for .Z ending files File uncompress all.Z7) for the file tar-xZf all.tar.z that ends with .tar.Z
In addition, for the common compressed files .zip and .rar under Windows, Linux also has methods to extract them:
1) for .zip
Zip and unzip programs are provided under linux. Zip is the compression program and unzip is the decompression program. There are many options for their parameters. Here is only a brief introduction, and an example is still given to illustrate their usage:
# zip all.zip * .jpg
This command compresses all .jpg files into a zip package:
# unzip all.zip
This command unzips all the files in all.zip.
2) for .rar
To process .rar files under linux, you need to install RAR for Linux. Download address: http://www.rarsoft.com/download.htm, download and install.
# tar-xzpvf rarlinux-x64-5.6.b5.tar.gz# cd rar# make
After installation, there are two programs: rar and unrar. Rar is the compression program and unrar is the decompression program. There are many options for their parameters. Here is only a brief introduction, and an example is still given to illustrate their usage:
# rar an all * .jpg
This command compresses all .jpg files into a rar package called all.rar, which automatically appends the .rar extension to the package name.
# unrar e all.rar
This command unzips all the files in all.rar:
Expand content
Tar-c: create compressed files-x: extract-t: view content-r: append files to the end of compressed archives-u: update files in the original package
These five are independent commands, one of which should be used for compression and decompression, which can be used with other commands, but only one of them can be used. The following parameters are optional when compressing or decompressing files as needed.
-z: with gzip attribute-j: with bz2 attribute-Z: with compress attribute-v: show all procedures-O: unpack the file to standard output
The following parameter-f is required:
-f: use the file name and remember that this parameter is the last parameter and can only be followed by the file name. # tar-cf all.tar * .jpg
This command is to type all .jpg files into a package called all.tar. -c means to generate a new package, and-f specifies the file name of the package.
# tar-rf all.tar * .gif
This command adds all .gif files to the all.tar package. -r means to add files.
# tar-uf all.tar logo.gif
This command updates the logo.gif file in the original tar package all.tar, and-u means to update the file.
# tar-tf all.tar
This command lists all the files in the all.tar package, and-t means to list files.
# tar-xf all.tar
This command unlocks all the files in the all.tar package, and-x means to unlock it.
Compress tar-cvf jpg.tar * .jpg / / package all jpg files in the directory into tar.jpgtar-czf jpg.tar.gz * .jpg / / package all jpg files in the directory into jpg.tar and compress them with gzip to generate a gzip compressed package named jpg.tar.gztar-cjf jpg.tar.bz2 * .jpg / / package all jpg files in the directory into jpg.tar and compress them with bzip2 Generate a bzip2 compressed package named jpg.tar.bz2tar-cZf jpg.tar.Z * .jpg / / package all the jpg files in the directory into jpg.tar, and compress it with compress to generate a umcompress compressed package named jpg.tar.Zrar a jpg.rar * .jpg / / rar format. You need to download rar for linuxzip jpg.zip * .jpg / / zip format first. You need to download zip for linux extract tar-xvf file.tar / / extract tar package tar-xzvf file.tar.gz / / extract tar.gztar-xjvf file.tar.bz2 / / extract tar.bz2tar-xZvf file.tar.Z / / extract tar.Zunrar e file.rar / / decompress rarunzip file.zip / / extract zip summary 1, * .tar extract 2 with tar-xvf, * .gz decompress 3 with gzip-d or gunzip, * .tar.gz and * .tgz with tar-xzf 4, * .bz2 with bzip2-d or bunzip2 with decompression 5, * .tar.bz2 with tar-xjf decompression 6, * .Z with uncompress decompression 7, * .tar.Z with tar-xZf decompression 8, * .rar with unrar e decompression 9, * zip decompression with unzip thank you for reading! This is the end of this article on "how to use tar commands in the linux system". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.