Linux tar Instructions

Source: Internet
Author: User
Tags rar

There are so many commands under Linux. Recently in the "Linux shell programming from beginner to proficient" book. The book has 468 pages, it's a pity that I'm not that kind of patient. An example of a person who follows, at most, sees something that is not clear and knocks at the code. If you want to really master the Linux shell programming, you really have to read a book such as gradual, at least some of you can understand some of the ideas, and from the network of those quick snippets you are not able to comprehend (hehe).

Get back to the lab tonight and see the tar command, about the tar command, I can only write TAR-XVF Xxx.tar, and even packaging how to write it is not clear, because the previous one really from the internet to move people over. Man tar is always a long speech, a lot of unimportant information mixed in, it is impossible to see. All right, let's be enlightened.

The following information can be seen through the tar--help.

-C Create a new profile. Select this option if the user wants to back up a directory or some files.
-R appends the file to be archived to the end of the archive file. For example, the user is ready to backup files, and found that there is a directory or some files forgot to back up, you can use this option to append the forgotten directories or files to the backup file.
-T lists the contents of the archive to see which files have been backed up.
-U update file. That is, replace the original backup file with the new file, if the file you want to update is not found in the backup file, append it to the end of the backup file.
-X releases the file from the archive file.
-F using a profile or device, this option is usually required.
-V Details the file information processed by tar. Without this option, TAR does not report file information.
-Z Compress/unzip the file with gzip, plus this option to compress the archive file, but you must also use this option to decompress when restoring.

The above is copied from the encyclopedia.

But there are a few things that are not clear, such as-f means using the file, followed by the file name. If you are creating a package, the created package uses it as the file name.

I want to practice one by one ....

First look at the contents of a directory (with the tree command), and now I want to create a package that contains all the files in this directory.

TAR-CF Achieve.rar./*

-C means creating a new package-F representation file, followed by the package name of the package to be achieve.rar, and finally the list of files we want to package. Enter and look:

Now check to see if the packages we created are correctly containing the files we need. TAR-TF Achieve.tar

You can see that the files are packaged correctly. Even the files in the directory are packaged recursively.

Now we are going to live with the package Achieve.tar add a new file file4, the command is as follows.

I really can't figure out why the argument to add the command is-R, which has something to do with the word append. I think this is also a lot of people who learn the common command of Linux often encountered problems. After all, Linux is not made by one person, practice makes perfect. When you hit this command 100 times, who cares if it's-append or-r?

OK, the last trick, unzip. This is one of the most frequent commands we use.

Note the-Z option, which means that the format of the compressed package that will be decompressed is compressed by gzip. The author of the book is very good, sometimes we do not need to know so many messy format, our purpose is simple, decompression only.

But if we use TAR-ZXVF Achieve.tar will be an error, see:

Gzip is a further compression of compressed files in the tar format. The file name extension is GZ, which is generally a compressed package in gzip format.

For the time being so much, other small functions can be found in the manual, after all, many times our purpose is very simple. Do not know this practice can not be called "take its essence, to its dross." Be smug.

Linux tar Instructions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.