English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux tar command

Linux Command大全

The Linux tar command (full name: tape archive) is used for file backup.

tar is a tool program used to create and restore backup files, it can add and extract files within the backup files.

Grammar

tar [-ABcdgGhiklmMoOpPrRsStuUvwWxzZ][-b <number of blocks>][-C <destination directory>][-f <backup file>][-F <Script file>][-K <file>][-L <media capacity>][-N <date and time>][-T <pattern file>][-V <volume name>][-X <pattern file>][-<device number><storage density>][--after-date=<date and time>][--atime-preserve][--backuup=<backup method>][--checkpoint][--concatenate][--confirmation][--delete][--exclude=<pattern style>][--force-local][--group=<group name>][--help][--ignore-failed-read][--new-volume-script=<Script file>][--newer-mtime][--no-recursion][--null][--numeric-owner][--owner=<username>][--posix][--erve][--preserve-order][--preserve-permissions][--record-size=<number of blocks>][--recursive-unlink][--remove-files][--rsh-command=<execution command>][--same-owner][--suffix=<backup string>][--totals][--use-compress-program=<execution command>][--version][--volno-file=<numbered file>][file or directory...]

parameters:

  • -A or--catenate append a new file to an existing backup file.
  • -b<number of blocks> or--blocking-factor=<number of blocks> set the number of blocks per record, with each block size of12Bytes.
  • -B or--read-full-records reset block size when reading data.
  • -c or--create create a new backup file.
  • -C<destination directory> or--directory=<destination directory> switch to the specified directory.
  • -d or--diff or--compare compare the differences 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> execute the specified Script file each time a tape is changed.
  • -g or--listed-incremental processing of a large number of GNU format backups.
  • -G or--incremental processing of a large number of old GNU format backups.
  • -h or--dereference Do not create symbolic links, directly copy the original file pointed to by the link.
  • -i or--ignore-zeros Ignore 0 Byte blocks in the backup file, that is, EOF.
  • -k or--keep-old-files Do not overwrite existing files when extracting backup files.
  • -K<file> or--starting-file=<file> Restore starting from the specified file.
  • -l or--one-file-system The file system where the copied files or directories are 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 capacity of each medium, unit is1024 Bytes calculation.
  • -m or--modification-time Do not change the modification time of the file when restoring the file.
  • -M or--multi-volume Use multi-volume mode when creating, restoring backup files, or listing their contents.
  • -N<date format> or--newer=<date and time> Only save files that have been updated after the specified date and time to the backup file.
  • -o or--old-archive or--portability Use V when writing data to the backup file.7format.
  • -O or--stdout Output the files restored from the backup file to the standard output device.
  • -p or--same-permissions Restore files with the original file permissions.
  • -P or--absolute-names Use absolute names for file names, do not remove the " symbol in front of the file name./" symbol.
  • -r or--append Add new files to the end of an existing backup file.
  • -R or--block-number List the block number of each information in the backup file.
  • -s or--same-order Restore the order of files to be the same as the order in the backup file.
  • -S or--sparse If a file contains a large number of consecutive 0 bytes, store this file as a sparse file.
  • -t or--list List the contents of the backup file.
  • -T<template file> or--files-from=<template file> Specify a template file containing one or more template styles, allowing tar to extract or create files that meet the set conditions.
  • -u or--update Only replace files that have been updated in the backup file.
  • -U or--unlink-first Unlink the file before decompressing and restoring the file.
  • -v or--verbose Display the execution process of the command.
  • -V<volume name> or--label=<volume name> Create backup files using the specified volume name.
  • -w or--interactive Ask the user first when encountering problems.
  • -W or--verify After writing to the backup file, confirm that the files are correct and error-free.
  • -x or--extract or--get Restore files from the backup file.
  • -X<pattern file> or--exclude-from=<pattern file> Specify a pattern file containing one or more pattern styles, so that ar excludes files that match the set conditions.
  • -z or--gzip or--ungzip Process backup files through the gzip command.
  • -Z or--compress or--uncompress Process backup files through the compress command.
  • -<device number><storage density> Set the device number for backup and the density of data storage.
  • --after-date=<date and time> The effect of this parameter is the same as specifying-N"parameter is the same.
  • --atime-preserve Do not change the access time of files.
  • --backup=<backup method> or--backup Backup files before removing files.
  • --checkpoint List directory names when reading backup files.
  • --concatenate The effect of this parameter is the same as specifying-The parameter is the same.
  • --confirmation The effect of this parameter is the same as specifying-w"parameter is the same.
  • --delete Delete the specified file from the backup file.
  • --exclude=<pattern style> Exclude files that match the pattern style.
  • --group=<group name> Set the group of the files added to the device file to the specified group.
  • --help Online help.
  • --ignore-failed-read Ignore data read errors and do not interrupt the execution of the program.
  • --new-volume-script=<Script file> The effect of this parameter is the same as specifying-F"parameter is the same.
  • --newer-mtime Only save files that have been changed.
  • --no-recursion Do not perform recursive processing, that is, do not process all files and subdirectories in the specified directory.
  • --null Read file names from the null device.
  • --numeric-owner Replace user names and group names with user ID and group ID.
  • --owner=<user name> Set the owner of the files added to the backup file to the specified user.
  • --posix Write data to backup files using POSIX format.
  • --preserve The effect of this parameter is the same as specifying-ps"parameter is the same.
  • --preserve-order The effect of this parameter is the same as specifying-The parameter is the same.
  • --preserve-permissions The effect of this parameter is the same as specifying"-p"parameters are the same.
  • --record-size=<block number> The effect of this parameter is the same as specifying"-b"parameters are the same.
  • --recursive-unlink Unlink all files in the directory before uncompressing the compressed file to restore the directory.
  • --remove-files Delete the file after it is added to the backup file.
  • --rsh-command=<execute command> Set the command to be executed on the remote host to replace the rsh command.
  • --same-owner Try to restore files with the same file owner.
  • --suffix=<backup tail string> Remove the file before making a backup.
  • --totals List file sizes after backup files are created.
  • --use-compress-program=<execute command> Process backup files through the specified command.
  • --version Display version information.
  • --volno-file=<numbered file> Use the number in the specified file to replace the default volume number.

Online Examples

Compressed File Non-Packed

# touch a.c       
# tar -czvf test.tar.gz a.c   //Compress a.c File to test.tar.gz
a.c

List the Content of the Compressed File

# tar -tzvf test.tar.gz 
-rw-r--r-- root/root     0 2010-05-24 16:51:59 a.c

Unzip Files

# tar -xzvf test.tar.gz 
a.c

Linux Command大全