首页
首页 » 备份压缩 » tar(tape archive)

tar(tape archive)

tar(tape archive)
功能说明:备份文件。
语  法:tar [-ABcdgGhiklmMoOpPrRsStuUvwWxzZ][-b <区块数目>][-C <目的目录>][-f <备份文件>][-F <Script文件>][-K <文件>][-L <媒体容量>][-N <日期时间>][-T <范本文件>][-V <卷册名称>][-X <范本文件>][-<设备编号><存储密度>][--after-date=<日期时间>][--atime-preserve][--backuup=<备份方式>][--checkpoint][--concatenate][--confirmation][--delete][--exclude=<范本样式>][--force-local][--group=<群组名称>][--help][--ignore-failed-read][--new-volume-script=<Script文件>][--newer-mtime][--no-recursion][--null][--numeric-owner][--owner=<用户名称>][--posix][--erve][--preserve-order][--preserve-permissions][--record-size=<区块数目>][--recursive-unlink][--remove-files][--rsh-command=<执行指令>][--same-owner][--suffix=<备份字尾字符串>][--totals][--use-compress-program=<执行指令>][--version][--volno-file=<编号文件>][文件或目录...]
补充说明:tar是用来建立,还原备份文件的工具程序,它可以加入,解开备份文件内的文件。
参  数:
  -A或--catenate   新增温暖件到已存在的备份文件。
  -b<区块数目>或--blocking-factor=<区块数目>   设置每笔记录的区块数目,每个区块大小为12Bytes。
  -B或--read-full-records   读取数据时重设区块大小。
  -c或--create   建立新的备份文件。
  -C<目的目录>或--directory=<目的目录>   切换到指定的目录。
  -d或--diff或--compare   对比备份文件内和文件系统上的文件的差异。
  -f<备份文件>或--file=<备份文件>   指定备份文件。
  -F<Script文件>或--info-script=<Script文件>   每次更换磁带时,就执行指定的Script文件。
  -g或--listed-incremental   处理GNU格式的大量备份。
  -G或--incremental   处理旧的GNU格式的大量备份。
  -h或--dereference   不建立符号连接,直接复制该连接所指向的原始文件。
  -i或--ignore-zeros   忽略备份文件中的0 Byte区块,也就是EOF。
  -k或--keep-old-files   解开备份文件时,不覆盖已有的文件。
  -K<文件>或--starting-file=<文件>   从指定的文件开始还原。
  -l或--one-file-system   复制的文件或目录存放的文件系统,必须与tar指令执行时所处的文件系统相同,否则不予复制。
  -L<媒体容量>或-tape-length=<媒体容量>   设置存放每体的容量,单位以1024 Bytes计算。
  -m或--modification-time   还原文件时,不变更文件的更改时间。
  -M或--multi-volume   在建立,还原备份文件或列出其中的内容时,采用多卷册模式。
  -N<日期格式>或--newer=<日期时间>   只将较指定日期更新的文件保存到备份文件里。
  -o或--old-archive或--portability   将资料写入备份文件时使用V7格式。
  -O或--stdout   把从备份文件里还原的文件输出到标准输出设备。
  -p或--same-permissions   用原来的文件权限还原文件。
  -P或--absolute-names   文件名使用绝对名称,不移除文件名称前的"/"号。
  -r或--append   新增文件到已存在的备份文件的结尾部分。
  -R或--block-number   列出每个信息在备份文件中的区块编号。
  -s或--same-order   还原文件的顺序和备份文件内的存放顺序相同。
  -S或--sparse   倘若一个文件内含大量的连续0字节,则将此文件存成稀疏文件。
  -t或--list   列出备份文件的内容。
  -T<范本文件>或--files-from=<范本文件>   指定范本文件,其内含有一个或多个范本样式,让tar解开或建立符合设置条件的文件。
  -u或--update   仅置换较备份文件内的文件更新的文件。
  -U或--unlink-first   解开压缩文件还原文件之前,先解除文件的连接。
  -v或--verbose   显示指令执行过程。
  -V<卷册名称>或--label=<卷册名称>   建立使用指定的卷册名称的备份文件。
  -w或--interactive   遭遇问题时先询问用户。
  -W或--verify   写入备份文件后,确认文件正确无误。
  -x或--extract或--get  从备份文件中还原文件。
  -X<范本文件>或--exclude-from=<范本文件>  指定范本文件,其内含有一个或多个范本样式,让ar排除符合设置条件的文件。
  -z或--gzip或--ungzip   通过gzip指令处理备份文件。
  -Z或--compress或--uncompress   通过compress指令处理备份文件。
  -<设备编号><存储密度>   设置备份用的外围设备编号及存放数据的密度。
  --after-date=<日期时间>   此参数的效果和指定"-N"参数相同。
  --atime-preserve   不变更文件的存取时间。
  --backup=<备份方式>或--backup   移除文件前先进行备份。
  --checkpoint   读取备份文件时列出目录名称。
  --concatenate   此参数的效果和指定"-A"参数相同。
  --confirmation   此参数的效果和指定"-w"参数相同。
  --delete   从备份文件中删除指定的文件。
  --exclude=<范本样式>   排除符合范本样式的问家。
  --group=<群组名称>   把加入设备文件中的文件的所属群组设成指定的群组。
  --help   在线帮助。
  --ignore-failed-read   忽略数据读取错误,不中断程序的执行。
  --new-volume-script=<Script文件>   此参数的效果和指定"-F"参数相同。
  --newer-mtime   只保存更改过的文件。
  --no-recursion   不做递归处理,也就是指定目录下的所有文件及子目录不予处理。
  --null   从null设备读取文件名称。
  --numeric-owner   以用户识别码及群组识别码取代用户名称和群组名称。
  --owner=<用户名称>   把加入备份文件中的文件的拥有者设成指定的用户。
  --posix   将数据写入备份文件时使用POSIX格式。
  --preserve      此参数的效果和指定"-ps"参数相同。
  --preserve-order      此参数的效果和指定"-A"参数相同。
  --preserve-permissions      此参数的效果和指定"-p"参数相同。
  --record-size=<区块数目>      此参数的效果和指定"-b"参数相同。
  --recursive-unlink   解开压缩文件还原目录之前,先解除整个目录下所有文件的连接。
  --remove-files   文件加入备份文件后,就将其删除。
  --rsh-command=<执行指令>   设置要在远端主机上执行的指令,以取代rsh指令。
  --same-owner   尝试以相同的文件拥有者还原问家你。
  --suffix=<备份字尾字符串>   移除文件前先行备份。
  --totals   备份文件建立后,列出文件大小。
  --use-compress-program=<执行指令>   通过指定的指令处理备份文件。
  --version   显示版本信息。
  --volno-file=<编号文件>   使用指定文件内的编号取代预设的卷册编号。

tar

tar [options] [tarfile] [other-files]

Copy files to or restore files from an archive medium. If any files are directories, tar acts on the entire subtree. Options need not be preceded by - (though they may be). The exception to this rule is when you are using a long-style option (such as --modification-time). In that case, the exact syntax is:

tar--long-option -function-options files

For example:

tar --modification-time -xvf tarfile.tar

Function options

You must use exactly one of these, and it must come before any other options:

-c, --create

Create a new archive.

-d, --diff, --compare

Compare the files stored in tarfile with other-files. Report any differences: missing files, different sizes, different file attributes (such as permissions or modification time).

--delete

Delete from the archive. This option cannot be used with magnetic tape.

-r, --append

Append other-files to the end of an existing archive.

-t, --list

Print the names of other-files if they are stored on the archive (if other-files are not specified, print names of all files).

-u, --update

Add files if not in the archive or if modified.

-x, --extract, --get

Extract other-files from an archive (if other-files are not specified, extract all files).

-A, --catenate, --concatenate

Concatenate a second tar file to the end of the first.

Options

[drive] [density]

Set drive (0-7) and storage density (l, m, or h, corresponding to low, medium, or high). Not available in all versions of tar.

--anchored

Exclude patterns must match the start of the filename (the default).

--atime-preserve

Preserve original access time on extracted files.

-b n, --blocking-factor=n

Set block size to n × 512 bytes.

--backup[=type]

Back up files rather than deleting them. If no backup type is specified, a simple backup is made with ~ as the suffix. (See also --suffix.) The possible values of type are:

t, numbered

Make numbered backups.

nil, existing

Make numbered backups if there are already numbered backups; otherwise make simple backups.

never, simple

Always make simple backups.

--checkpoint

List directory names encountered.

--exclude=pattern

Remove files matching pattern from any list of files.

-f file, --file=file

Store files in or extract files from archive file. Note that file may take the form hostname:filename.

--force-local

Interpret filenames in the form hostname:filename as local files.

-g file, --listed-incremental=file

Create new-style incremental backup.

--group=group

Use group as the group for files added to the archive.

-h, --dereference

Dereference symbolic links, and archive the files they point to rather than the symbolic link.

--help

Print help message and exit.

-i, --ignore-zeros

Ignore zero-sized blocks (i.e., EOFs).

--ignore-case

Ignore case when excluding files.

--ignore-failed-read

Ignore unreadable files to be archived. Default behavior is to exit when encountering these.

-j, --I, --bzip

Compress files with bzip2 before archiving them, or uncompress them with bunzip2 before extracting them.

-l, --one-file-system

Do not archive files from other filesystems.

-k, --keep-old-files

When extracting files, do not overwrite files with similar names. Instead, print an error message.

-m, --modification-time, --touch

Do not restore file modification times; update them to the time of extraction.

--mode=permissions

Use permissions when adding files to an archive. The permissions are specified the same way as for the chmod command.

--newer-mtime=date

Add only files whose contents have changed since date to the archive.

--no-anchor

Exclude patterns may match anything following a slash.

--no-ignore-case

Do not ignore case when excluding files.

--no-same-permissions

Do not extract permissions information when extracting files from the archive. This is the default for users, and therefore affects only the superuser.

--no-recursion

Do not move recursively through directories.

--no-same-owner

When extracting, create files with yourself as owner.

--no-wildcards

Don't use wildcards when excluding files; treat patterns as strings.

--no-wildcards-match-slash

Wildcards do not match / when excluding files.

--null

Allow filenames to be null-terminated with -T. Override -C.

--numeric-owner

Use the numeric owner and group IDs rather than the names.

-o, --old-archive, --portability

Create old-style archive in Unix V7 rather than ANSI format.

--overwrite

Overwrite existing files and directory metadata when extracting from archive.

--overwrite-dir

Overwrite existing directory metadata when extracting from archive.

--owner=owner

Set owner as the owner of extracted files instead of the original owner. owner is first assumed to be a username, then, if there is no match, a numeric user ID.

-p, --same-permissions, --preserve-permissions

Keep permissions of extracted files the same as the originals.

--posix

Create a POSIX-compliant archive.

--preserve

Equivalent to invoking both the -p and -s options.

--record-size=size

Treat each record as having size bytes, where size is a multiple of 512.

--recursion

Move recursively through directories.

--recursive-unlink

Remove existing directory hierarchies before extracting directories with the same name.

--remove-files

Remove originals after inclusion in archive.

--rsh-command=command

Do not connect to remote host with rsh; instead, use command.

-s, --same-order, --preserve-order

When extracting, sort filenames to correspond to the order in the archive.

--same-owner

When extracting, create files with the same ownership as the originals.

--show-omitted-dirs

List directories being omitted when operating on an archive.

--suffix=suffix

Use suffix instead of the default ~ when creating a backup file.

--totals

Print byte totals.

--use-compress-program=program

Compress archived files with program, or uncompress extracted files with program.

-v, --verbose

Verbose. Print filenames as they are added or extracted.

--version

Print version information and exit.

--volno-file=file

Use/update the volume number in file.

-w, --interactive, --confirmation

Wait for user confirmation (y) before taking any actions.

--wildcards

Use wildcards when excluding files.

--wildcards-match-slash

Wildcards match / when excluding files.

-z, --gzip, --gunzip, --ungzip

Compress files with gzip before archiving them, or uncompress them with gunzip before extracting them.

-B, --read-full-records

Reblock while reading; used for reading from 4.2BSD pipes.

-C directory, --directory=directory

cd to directory before beginning tar operation.

-F script, --info-script=script, --new-volume-script=script

Implies -M (multiple archive files). Run script at the end of each file.

-G, --incremental

Create old-style incremental backup.

-K file, --starting-file=file

Begin tar operation at file in archive.

-L length, --tape-length=length

Write a maximum of length × 1024 bytes to each tape.

-M, --multivolume

Expect archive to be multivolume. With -c, create such an archive.

-N date, --newer=date, --after-date=date

Ignore files older than date.

-O, --to-stdout

Print extracted files to standard output.

-P, --absolute-names

Do not remove initial slashes (/) from input filenames.

-R, --block-number

Display archive's block number in messages.

-S, --sparse

Treat sparse files more efficiently when adding to archive.

-T file, --files-from=file

Consult file for files to extract or create.

-U, --unlink-first

Remove each existing file from the filesystem before extracting from the archive.

-V name, --label=name

Name this volume name.

-W, --verify

Check archive for corruption after creation.

-X file, --exclude-from file

Consult file for list of files to exclude.

-Z, --compress, --uncompress

Compress files with compress before archiving them, or uncompress them with uncompress before extracting them.

Examples

Create an archive of /bin and /usr/bin (c), show the command working (v), and store on the tape in /dev/rmt0:

tar cvf /dev/rmt0 /bin /usr/bin

List the tape's contents in a format like ls -l:

tar tvf /dev/rmt0

Extract the /bin directory:

tar xvf /dev/rmt0 /bin

Create an archive of the current directory and store it in a file backup.tar:

tar cvf - `find . -print` > backup.tar

(The - tells tar to store the archive on standard output, which is then redirected.)

Filter an archive through gzip, extracting the contents but leaving the original file compressed:

tar xvfz chapters.tar.gz