Scroll to navigation

TAR(1) tar TAR(1)

名字

tar - tar 檔案文件管理程序的 GNU 版本。

總覽

tar <操作參數> [選項]

操作參數:

[-]A --catenate --concatenate
[-]c --create
[-]d --diff --compare
[-]r --append
[-]t --list
[-]u --update
[-]x --extract --get
--delete

常用選項:

-C, --directory 目錄
-f, --file 文件
-j, --bzip2
-J, --xz
-p, --preserve-permissions
-v, --verbose
-z, --gzip

所有選項:
[ -a, --auto-compress ] [ --add-file 文件 ] [ --anchored ] [ --atime-preserve ] [ -b, --blocking-factor N ] [ -B, --read-full-records ] [ --backup[=備份類型] ] [ --block-compress ] [ -C, --directory 目錄 ] [ --checkpoint ] [ --delay-directory-restore ] [ --exclude 文件或目錄 ] [ --exclude-caches ] [ --exclude-caches-all ] [ --exclude-caches-under ] [ --exclude-tag 文件 ] [ --exclude-tag-all 文件 ] [ --exclude-tag-under 文件 ] [ -f, --file [主機名:]文件 ] [ -F, --info-script 文件, --new-volume-script 文件 ] [ --force-local ] [ --format 格式 ] [ -g, --listed-incremental 快照 ] [ -G, --incremental ] [ --group 組 ] [ -h, --dereference ] [ --help ] [ -i, --ignore-zeros ] [ -I, --use-compress-program 程序 ] [ --ignore-case ] [ --ignore-command-error ] [ --ignore-failed-read ] [ --index-file 文件 ] [ -j, --bzip2 ] [ -J, --xz ] [ -k, --keep-old-files ] [ -K, --starting-file 文件 ] [ --keep-newer-files ] [ -l, --check-links ] [ -L, --tape-length N ] [ --lzip ] [ --lzma ] [ --lzop ] [ -m, --touch, --modification-time ] [ -M, --multi-volume ] [ --mode 權限 ] [ --mtime 日期 ] [ -N, --after-date 日期, --newer 日期 ] [ --newer-mtime 日期 ] [ --no-anchored ] [ --no-auto-compress ] [ --no-delay-directory-restore ] [ --no-ignore-case ] [ --no-ignore-command-error ] [ --no-overwrite-dir ] [ --no-quote-chars ] [ --no-recursion ] [ --no-same-permissions ] [ --no-unquote ] [ --no-wildcards ] [ --no-wildcards-match-slash ] [ --null ] [ --numeric-owner ] [ -o, --old-archive, --portability, --no-same-owner ] [ -O, --to-stdout ] [ --occurrence 次數 ] [ --one-file-system ] [ --overwrite ] [ --overwrite-dir ] [ --owner 用戶 ] [ -p, --same-permissions, --preserve-permissions ] [ -P, --absolute-names ] [ --pax-option 關鍵字列表 ] [ --posix ] [ --preserve ] [ --quote-chars 字符串 ] [ --quote-style 風格 ] [ -R, --block-number ] [ --record-size 字節數 ] [ --recursion ] [ --recursive-unlink ] [ --remove-files ] [ --restrict ] [ --rmt-command 命令 ] [ --rsh-command 命令 ] [ -s, --same-order, --preserve-order ] [ -S, --sparse ] [ --same-owner ] [ --show-defaults ] [ --show-omitted-dirs ] [ --show-transformed-names, --show-stored-names ] [ --strip-components 目錄層數 ] [ --suffix 後綴 ] [ -T, --files-from 文件 ] [ --test-label ] [ --to-command 命令 ] [ --transform sed表達式 ] [ --totals ] [ -U, --unlink-first ] [ --unquote ] [ --utc ] [ -v, --verbose ] [ -V, --label 名稱 ] [ --version ] [ --volno-file 文件 ] [ -w, --interactive, --confirmation ] [ -W, --verify ] [ --wildcards ] [ --wildcards-match-slash ] [ -X, --exclude-from 文件 ] [ -z, --gzip, --gunzip, --ungzip ] [ -Z, --compress, --uncompress ] [ -[0-7][lmh] ]

描述

這是tar的GNU版本的手冊頁。 tar是一個用於儲存或提取tar文件的程序。 tar文件可放在磁盤中, 也可以存爲普通文件。 tar 的第一個參數必須是操作參數A、c、d、r、t、u、x 中的一個, 參數後面可跟着任意可選選項。 tar的最後一個參數是你要處理的文件或目錄的名字。 如果你指定了一個目錄, 該目錄的所有子目錄都將被加入存檔。

應用舉例

tar -xvf foo.tar
提取 foo.tar 文件並顯示提取過程
tar -xzf foo.tar.gz
提取用 gzip 壓縮的文件 foo.tar.gz
tar -cjf foo.tar.bz2 bar/
用 bzip 爲目錄 bar 創建一個叫做 foo.tar.bz2存檔
tar -xjf foo.tar.bz2 -C bar/
把用 bzip 壓縮的文件 foo.tar.bz2 提取到 bar 目錄
tar -xzf foo.tar.gz blah.txt
把文件 blah.txt 從 foo.tar.gz 中提取出來

注意: 當壓縮或提取的時候, 壓縮類型選項常常是不必需的, 因爲tar會根據文件的後綴自動選擇壓縮類型。

參數說明

下列參數中必須有至少一個被使用:
-A, --catenate, --concatenate
將一存檔與已有的存檔合併
-c, --create
創建一個新的存檔
-d, --diff, --compare
比較存檔與相應的未存檔文件的不同之處
-r, --append
將文件附加到存檔結尾
-t, --list
列出存檔中文件的目錄
-u, --update
僅將較新的文件附加到存檔中
-x, --extract, --get
從存檔提取文件
--delete
把指定文件從存檔中刪除(不要用於磁帶!)

常用選項

-C, --directory 目錄
提取存檔到指定目錄
-f, --file [主機名:]文件
指定存檔或設備中的文件 (默認是 "-", 表示 標準輸入/輸出)
-j, --bzip2
用 bzip2 處理存檔; 用於 .bz2 文件
-J, --xz
用 xz 處理存檔; 用於 .xz 文件
-p, --preserve-permissions
提取所有保護信息
-v, --verbose
顯示文件處理過程
-z, --gzip, --ungzip
用 gzip 處理存檔; 用於 .gz 文件

所有選項

-a, --auto-compress
根據存檔後綴來選擇壓縮程序
--add-file 文件
添加指定文件到存檔 (對以下標線開頭的文件很有用)
--anchored
patterns will match the start of file names
--atime-preserve
不改變存檔中文件的訪問時間
-b, --blocking-factor N
指定塊大小爲 Nx512 字節(默認N=20)
-B, --read-full-blocks
讀取時重組塊 (用於讀取4.2BSD pipes)
--backup[=備份類型]
備份文件而不是刪除它們, 備份類型有simple、numbered等
--block-compress
讓磁帶的輸出結果成塊輸出
-C, --directory 目錄
提取文檔到指定目錄
--checkpoint
讀取存檔時顯示目錄名
--delay-directory-restore
延遲對已提取目錄的修改時間和權限的設定, 直到提取結束
--exclude 文件或目錄
排除指定文件或目錄
--exclude-caches
排除帶有 緩存目錄 標記的目錄
--exclude-tag 文件
排除包含指定文件的目錄
-f, --file [主機名:]文件
指定存檔或設備中的文件 (默認是 "-", 表示 標準輸入/輸出)
-F, --info-script 文件, --new-volume-script 文件
在每卷磁帶的結尾運行腳本 (會應用--multi-volume選項)
--force-local
存檔文件是本地的, 即使它的名稱中含有冒號
--format FORMAT
選擇創建存檔的格式
v7 - Unix V7
oldgnu - GNU tar <=1.12
gnu - GNU tar 1.13
ustar - POSIX.1-1988
posix - POSIX.1-2001
    
-g, --listed-incremental 快照
創建/列出/提取 新GNU格式的增量備份
--group
將添加到存檔的文件的組標識設置爲指定組, 而不是源文件所在的組; 這個選項對提取無效
-G, --incremental
創建/列出/提取 舊GNU格式的增量備份
-h, --dereference
不存入符號鏈接; 存入鏈接指向的文件
--help
顯示像本手冊這樣的幫助信息, 但不像這麼詳細
-i, --ignore-zeros
忽略存檔中的 0 字節塊 (那通常意味着文件結束)
-I, --use-compress-program 程序
通過指定程序訪問存檔 (該程序通常是一個壓縮程序; 它需能接受 -d 參數)
--ignore-case
排除文件時不區分大小寫
--ignore-command-error
忽略子程序的退出代碼
--ignore-failed-read
遇到不可讀文件的非零狀態不退出
--index-file 文件
將處理過程信息輸出到指定文件, 而不是輸出到標準輸出
-j, --bzip2
用 bzip2 處理存檔, 用於 .bz2 文件
-J, --xz
用 xz 處理存檔, 用於 .xz 文件
-k, --keep-old-files
保留已存在的文件; 不用存檔中的文件覆蓋它們
-K, --starting-file FILE
從存檔中的指定文件處開始
--keep-newer-files
不覆蓋比存檔新的文件
-l, --check-links
如果文件系統中文件的硬鏈接數和存檔中記錄的不同, 則發出警告
-L, --tape-length N
在寫入了N*1024字節後, 更換磁帶
-m, --touch, --modification-time
不提取文件的修改時間
-M, --multi-volume
創建/列出/提取 多卷存檔
--mode 權限
添加文件時應用指定的權限 (參看 chmod(1))
--mtime 日期
當創建存檔時, 使用指定日期作爲存檔成員的修改日期, 而不是使用文件的實際修改時間
-N, --after-date 日期, --newer 日期
只存儲在指定日期後有修改或狀態更新 (權限, ACLs, 擴展屬性, ...)的文件
--newer-mtime 日期
和 --newer 類似, 但是隻存儲指定日期後有修改的文件
--no-anchored
匹配任意‘/’後字符項--exclude一起使用
--no-auto-compress
不根據存檔後綴來決定使用哪個壓縮程序
--no-delay-directory-restore
在目錄中的所有文件都被提取完成時, 就設定該目錄的修改時間和權限; 這是默認設置
--no-ignore-command-error
對以非零狀態終止的子程序的顯示警告
--no-ignore-case
用 --exclude 匹配時區分大小寫
--no-overwrite-dir
從存檔中提取文件時, 保留已存在目錄的元數據。
--no-quote-chars 字符串
把指定字符串中的字符從--quote-chars選項指定的字符中去除
--no-recursion
不遞歸進入子目錄
--no-same-permissions
提取時應用用戶的umask, 而不是用已記錄的權限
--no-unquote
將所有輸入文件或成員的名字作爲普通文字, 不解釋轉義序列
--no-wildcards
不對--exclude使用通配符
--no-wildcards-match-slash
--exclude的通配符不匹配斜槓(/)
--null
--files-from讀取以空值終止的名字, 禁用--directory
--numeric-owner
總是用數字作爲 用戶/組 的名字
-o, --old-archive, --portability
相當於--format=v7; 當創建存檔時-o選項表示這個行爲 (已棄用的行爲)
-o, --no-same-owner
提取時不恢復所有權; 當提取時-o選項表示這個行爲
-O, --to-stdout
將文件提取到標準輸出
--occurrence 次數
只處理指定次數每個已被命名的文件的在操作中的出現; 用於--delete, --diff, --extract, 或 --list
--one-file-system
創建存檔時停留在本地文件系統
--overwrite
提取時覆蓋已存在的文件和目錄中的元數據
--overwrite-dir
提取時覆蓋目錄中的元數據
--owner 用戶
將文件所有者設爲指定用戶, 而不是原文件的所有者; 這個選項對提取無效
-p, --preserve-permissions, --same-permissions
提取所有保護信息
-P, --absolute-names
將文件名開頭的“/”符號看作文件名的一部分
--pax-option 關鍵字列表
修改tar處理擴展頭關鍵字的方式, 只用於POSIX.1-2001存檔
--posix
相當於--format=posix
--preserve
相當於--preserve-permissions加上--same-order
--quote-chars 字符串
總是標出指定字符串中包含的的字符, 即使已選擇的標識風格不標識它們
--quote-style 風格
設定顯示成員和文件名稱的標識風格
-R, --record-number
顯示存檔中每條信息的記錄數字
--record-size 字節數
訪問存檔時每條記錄使用指定的字節數
--recursion
遞歸進入目錄
--recursive-unlink
提取目錄之前先把存在的相同名稱的目錄刪除
--remove-files
把文件加入到存檔後刪除這些文件
--restrict
禁用一些有潛在害處的選項; 目前這會禁用多卷菜單中對shell的調用
--rmt-command 命令
用指定的命令代替默認的/usr/sbin/rmt
--rsh-command 命令
用指定的遠程命令代替rsh(1)
-s, --same-order, --preserve-order
名稱列表會被排序以匹配存檔
-S, --sparse
高效地處理稀疏文件
--same-owner
以相同的所有權創建提取出的文件
--show-defaults
顯示tar使用的默認選項
--show-omitted-dirs
顯示提取時tar跳過的目錄
--show-transformed-names, --show-stored-names
應用了任何sed轉換之後, 顯示文件或成員名字
--strip-components 目錄層數
在提取前, 把文件從前往後指定層數的目錄都從提取路徑中去掉, 如果文件包含在指定層數中, 則不被提取
--suffix 後綴
備份文件時, 使用指定的後綴, 而不是使用默認後綴‘~’
-T, --files-from 文件
從指定文件中獲得要提取或創建的存檔的名字
--test-label
讀取卷標; 如果一個詞被指定了, 則測試它是否匹配這個卷標
--to-command 命令
提取期間, 將提取的文件導入到指定命令的標準輸入
--totals
顯示用--create參數寫入的總字節數
--transform sed表達式
sed的轉換表達式轉換文件或成員的名字
-U, --unlink-first
提取文件之前,刪除已存在的與之同名的文件
--unquote
不標識輸入文件或成員的名字; 這是默認選項
--utc
以UTC時間顯示文件的修改日期
-v, --verbose
列出文件的處理情況
-V, --label 名稱
用指定卷名創建存檔
--version
顯示tar程序的版本信息
--volno-file 文件
保持追蹤指定文件中多卷存檔的卷編號; 和--multi-volume一起使用
-w, --interactive, --confirmation
每一個動作都要求確認
-W, --verify
寫完存檔後對其進行校驗
--wildcards
--exclude用通配符
--wildcards-match-slash
--exclude的通配符匹配斜槓(/)
-X, --exclude-from 文件

排除列在指定文件中的文件

-z, --gzip, --gunzip, --ungzip
用gzip對存檔進行操作
-Z, --compress, --uncompress
用compress對存檔進行操作
-[0-7][lmh]
指定驅動器[0-7]和壓縮密度[低中高]

BUGS

GNU世界的人, 通常不喜歡man手冊, 而是寫文檔代替之。 tar的維護者也是如此。 所以, 這個man手冊頁可能會不完全, 或者不夠新, 它被包含在Gentoo的portage樹中, 因爲man是一個非常好的工具:)。 這個man手冊頁最初取自Debian Linux, 從那時起已在這裏被很好地更新。

報告 BUGS

請通過 http://bugs.gentoo.org/ 報告Bug。 翻譯問題請聯繫譯者或到 https://github.com/lidaobing/manpages-zh/ 提交問題

作者

Debian Linux http://www.debian.org/
Mike Frysinger <vapier@gentoo.org>

譯者

CMPP 中文手冊頁計劃 http://cmpp.linuxforum.net (2001/08/08)
Saigut <gosaigut@gmail.com> (2013/11/09)

中文版最新更新

2014/10/04

本頁面中文版由中文 man 手冊頁計劃提供。
中文 man 手冊頁計劃:https://github.com/man-pages-zh/manpages-zh
Mar 2010 GNU