Linux tar command

Source: Internet
Author: User

Tar command

Tar can create archives for files and directories. The tar user can create files for a specific file (backup file), change files in the file, or add new files to the file. With the tar command, you can package a whole bunch of files and directories into a single file, which is useful for backing up files or combining several files into one file for easy network transmission.

Syntax: tar [main option + Secondary options] file or directory

When using this command, the main option is required, and it tells Tar what to do, auxiliary options are auxiliary and can be used.

Main options:

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, you can use this option to append a forgotten directory or file to a backup file if you have already made a backup file and you find that there is a directory or some files that you forgot to back up.

T list the contents of the archive file and 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 release the file from the archive file.

Accessibility Options:

b This option is set for the tape drive. It is followed by a number that indicates the size of the chunk and the system preset value is (20*512 bytes).

F using a file or device, this option is usually required.

K Save the file that already exists. For example, we restore a file, during the restore process, encountered the same file, will not be overwritten.

m when restoring files, set the modification time of all files to now.

M Create a multi-volume archive file for storage on several disks.

V Detailed report of file information processed by tar. Without this option, TAR does not report file information.

W each step requires confirmation.

Use gzip to compress/unzip the file, plus this option to compress the archive file, but be sure to unzip it using this option when restoring.

Example 1: The Home/home directory including its subdirectories are all backup files, the backup file name is Usr.tar.

$ tar cvf usr.tar/home

Example 2: The home/home directory including its subdirectories are all backup files, and compression, backup file name is usr.tar.gz.

$ tar czvf usr.tar.gz/home

Example 3: Restore and decompress the usr.tar.gz backup file.

$ tar xzvf usr.tar.gz

Example 4: View the contents of the Usr.tar backup file and display it on the display in Split-screen mode.

$ tar TVF Usr.tar | More

To back up a file to a specific device, simply use the device name as the backup file name.

Example 5: The user creates a backup file on the floppy disk of the/DEV/FD0 device and copies all the files in the/home directory to the backup file.

$ tar Cf/dev/fd0/home

To restore files from your device's disk, use the XF option:

$ tar xf/dev/fd0

If a user backs up a file that is larger than the storage space available to the device, such as a floppy disk, you can create a multi-volume tar backup file. The M option instructs the tar command to prompt you to use a new storage device, and when the M option is used to archive a floppy drive, the TAR command reminds you to put a new floppy disk when a floppy disk is full. This allows you to save the tar file to several disks.


Linux tar command

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.