Exclude a folder or file when using the tar command to compress

Source: Internet
Author: User
Tags log log

Generally a folder such as log with tar is easy to pack

The code is as follows Copy Code
TAR-ZCVF log.tar.gz Log

Just use the above command.

1. Exclude folder:
But in the production environment log file is very large, there are dozens of G, we do not need to backup, examples exclude PROFTPD log.
I checked it out on the Internet, and the tar--exclude seems to work.

The code is as follows Copy Code
TAR-ZCVF log.tar.gz--exclude=log/proftpd/log

But this will still pack all the PROFTPD log files in.

Then tried many times to know that the correct wording should be

The code is as follows Copy Code
TAR-ZCVF log.tar.gz--exclude=log/proftpd Log

Because the TAB key in Linux automatically complements the full path, the folder will be followed by/symbol, which leads to the inability to exclude.

2. Exclude Documents
Excluding files is simple, such as excluding Log/proftpd/proftpd.log

  code is as follows copy code
TAR-ZCVF log.tar.gz--exclude=log/proftpd/proftpd.log log


tar command
1. Action The TAR command is a reliable method of backing up files in a unix/linux system and can work almost anywhere, with permissions for all users.
2. Format tar [main options + auxiliary options] File or directory   eg:  tar zxvf libiconv-1.13.tar.gz ./libiconv    tar cxvf libic onv-1.13.tar.gz./*.php
3. Main parameters
When you use this command, the main option is required, it tells Tar what to do, the auxiliary option is auxiliary, and you can choose.
3.1 Main options:
-C To create a new profile. If the user wants to back up a directory or some files, select this option.
-R Appends the file you want to archive to the end of the archive file. For example, users have done backup files, and found that there is a directory or some files have forgotten to back up, you can use this option to append forgotten directories or files to the backup file.
-T lists the contents of the profile to see which files have been backed up.
-u updates the file. That is, replace the original backup file with the new file, and append it to the end of the backup file if the file you want to update cannot be found in the backup file.
-X frees the file from the profile.
3.2 Accessibility Options:
-B This option is set for the tape drive followed by a number that indicates the size of the block and the system preset is 20x512 bytes.
-F uses an archive file or device, which is usually a required choice.
-K saves files that already exist. For example, if you restore a file, you will encounter the same file during the restore process without overwriting.
-M when the file is restored, the modification time for all files is set to now.
-M creates a multiple-volume profile for storage on several disks.
-V reports the file information processed by tar in detail. Without this option, TAR does not report file information.
-W requires confirmation each step.
-Z compresses/unzip the file with gzip, plus this option to compress the profile, but you must also use this option for decompression when restoring

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.