[Linux] [tar] czvf and xzvf of tar command

The Linux tar (tape archive) command is mainly used to pack, compress and decompress files. The original design purpose of the command is to back up files to tape (tapearchive), hence the name tar.

1. Examples of commonly used tar commands

①Packing command, tar -czvf xxx:

Description: The tar -czvf file.tar.gz file1.txt file2.txt file3.txt command compresses and packs the files file1.txt, file2.txt, and file3.txt into a file.tar.gz compressed package;

②Decompression command, tar -xzvf xxx:

Description: The tar -xzvf file.tar.gz command decompresses the compressed file file.tar.gz (file1.txt & file2.txt & file3.txt)

2. tar common command parameter description

The meanings of the czvf/xzvf parameters of the tar command are as follows:

  • -c or --create to create a new backup file.
  • -x or --extract or --get restore files from backup files.
  • -z or --gzip or --ungzip Process the backup file through the gzip command.
  • -v or --verbose display the command execution process.
  • -f<backup file> or --file=<backup file> Specify the backup file.

Take the parameter v as an example. If the tar compression command is packaged without the parameter v, it will not show which files are packaged during the execution of the command. The comparison is as follows:

3. Appendix-complete parameters

  • -A or --catenate add files to the existing backup file.
  • -b<number of blocks> or --blocking-factor=<number of blocks> Set the number of blocks for each record, each block size is 12Bytes.
  • -B or --read-full-records Reset the block size when reading data.
  • -c or --create to create a new backup file.
  • -C<destination directory> or --directory=<destination directory> Switch to the specified directory.
  • -d or --diff or --compare Compare the difference between the files in the backup file and the files on the file system.
  • -f<backup file> or --file=<backup file> Specify the backup file.
  • -F<Script file> or --info-script=<Script file> Each time the tape is changed, the specified Script file is executed.
  • -g or --listed-incremental handles a large number of backups in GNU format.
  • -G or --incremental Process large backups of the old GNU format.
  • -h or --dereference does not establish a symbolic link, and directly copies the original file pointed to by the link.
  • -i or --ignore-zeros Ignore the 0 Byte block in the backup file, which is EOF.
  • -k or --keep-old-files does not overwrite existing files when unpacking backup files.
  • -K<file> or --starting-file=<file> Start restoration from the specified file.
  • -l or --one-file-system The file system where the copied file or directory is stored must be the same as the file system where the tar command is executed, otherwise it will not be copied.
  • -L<media capacity> or -tape-length=<media capacity> Set the storage capacity of each body, the unit is calculated in 1024 Bytes.
  • -m or --modification-time When restoring a file, the modification time of the file is not changed.
  • -M or --multi-volume When creating, restoring a backup file or listing its contents, use the multi-volume mode.
  • -N<date format> or --newer=<date time> Only save files that are newer than the specified date to the backup file.
  • -o or --old-archive or --portability Use V7 format when writing data to the backup file.
  • -O or --stdout output the restored file from the backup file to the standard output device.
  • -p or --same-permissions restore the file with the original file permissions.
  • -P or --absolute-names Use absolute file names without removing the "/" sign before the file name.
  • -r or --append adds a file to the end of the existing backup file.
  • -R or --block-number lists the block number of each message in the backup file.
  • -s or --same-order The order of the restored files is the same as the storage order in the backup file.
  • -S or --sparse If a file contains a large number of consecutive 0 bytes, save the file as a sparse file.
  • -t or --list lists the contents of the backup file.
  • -T<template file> or --files-from=<template file> Specify a template file, which contains one or more template styles, let tar unzip or create a file that meets the set conditions.
  • -u or --update Only replace files that are newer than the files in the backup file.
  • -U or --unlink-first Unlink the compressed file before restoring the file, first unlink the file.
  • -v or --verbose display the command execution process.
  • -V<volume name> or --label=<volume name> Create a backup file using the specified volume name.
  • -w or --interactive Ask the user first when encountering problems.
  • -W or --verify After writing the backup file, confirm that the file is correct.
  • -x or --extract or --get restore files from backup files.
  • -X<template file> or --exclude-from=<template file> Specify a template file, which contains one or more template styles, and let ar exclude files that meet the set conditions.
  • -z or --gzip or --ungzip Process the backup file through the gzip command.
  • -Z or --compress or --uncompress Process the backup file through the compress command.
  • -<device number><storage density> Set the peripheral device number for backup and the density of stored data.
  • --after-date=<date time> The effect of this parameter is the same as specifying the "-N" parameter.
  • --atime-preserve does not change the file access time.
  • --backup=<backup method> or --backup Perform backup before removing files.
  • --checkpoint List the directory name when reading the backup file.
  • --concatenate The effect of this parameter is the same as specifying the "-A" parameter.
  • --confirmation The effect of this parameter is the same as specifying the "-w" parameter.
  • --delete Delete the specified file from the backup file.
  • --exclude=<template style> Exclude files that match the template style.
  • --group=<group name> Set the group of the file added to the device file to the specified group.
  • --help Online help.
  • --ignore-failed-read Ignore data reading errors without interrupting the execution of the program.
  • --new-volume-script=<Script file> The effect of this parameter is the same as specifying the "-F" parameter.
  • --newer-mtime Only save changed files.
  • --no-recursion Do not perform recursive processing, that is, all files and subdirectories in the specified directory will not be processed.
  • --null Read the file name from the null device.
  • --numeric-owner Replace user name and group name with user ID and group ID.
  • --owner=<user name> Set the owner of the file added to the backup file to the specified user.
  • --posix Use POSIX format when writing data to the backup file.
  • --preserve The effect of this parameter is the same as specifying the "-ps" parameter.
  • --preserve-order The effect of this parameter is the same as specifying the "-A" parameter.
  • --preserve-permissions The effect of this parameter is the same as specifying the "-p" parameter.
  • --record-size=<number of blocks> The effect of this parameter is the same as specifying the "-b" parameter.
  • --recursive-unlink Before unpacking the compressed file and restoring the directory, first unlink all files in the entire directory.
  • --remove-files After the file is added to the backup file, delete it.
  • --rsh-command=<execute command> Set the command to be executed on the remote host to replace the rsh command.
  • --same-owner Attempts to restore the file with the same file owner.
  • --suffix=<backup suffix string> Back up the file before removing it.
  • --totals After the backup file is created, list the file size.
  • --use-compress-program=<execute command> Process the backup file through the specified command.
  • --version Display version information.
  • --volno-file=<numbered file> Replace the preset volume number with the number in the specified file.

4. References

https://www.runoob.com/linux/linux-comm-tar.html

https://zhidao.baidu.com/question/1431240737888921659.html

 

 

Guess you like

Origin blog.csdn.net/u010521062/article/details/113918972