Search  

tar 壓縮解壓縮zip tgz  
tar 壓縮整個目錄
tar zcf 2ns.tar 2ns/
將整個目錄2ns,壓縮到檔案2ns.tar

tar 解壓縮到特定目錄
tar -xf 2ns.tar -C /tmp
2ns.tar壓縮檔,解壓縮到目錄 /tmp


指令詳細說明
用法: tar [選項…] [FILE]…
GNU 'tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.

Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.

主要操作模式:

-A, --catenate, --concatenate 加入 tar 檔案到封存中
-c, --create 建立新的封存
-d, --diff, --compare 在封存與檔案系統之間找出差異
--delete 從封存中刪除 (並非在磁帶上!)
-r, --append 加入檔案到封存末端
-t, --list 列出封存的內容
--test-label 測試封存卷冊標籤然後離開
-u, --update 只加入比封存中複本還新的檔案
-x, --extract, --get 從封存中解開檔案

運算變更項:

--check-device 檢查裝置數量時建立遞增檔案 (預設)
-g, --listed-incremental=檔案
處理新型 GNU-格式之遞增備份
-G, --incremental 處理舊型 GNU-格式之遞增備份
--ignore-failed-read
離開無法讀取的檔案時不要回傳非零的值
--level=數目 用於建立 listed-incremental
封存的傾印等級
-n, --seek 封存是可尋指的
--no-check-device 不檢查裝置數量時建立遞增檔案
--no-seek 封存不是可尋指的
--occurrence[=數目] 只有對於每一個在封存中第 NUM
個出現的檔案才會處理。此選項只有與
--delete、--diff、--extract 或 --list
等次命令之一合併使用時才有效,而且要經由命令列或是
-T
選項來提供一個檔案序列。預設的數目是
1。
--sparse-version=MAJOR[.MINOR]
設定稀疏格式版本以使用 (意味著
--sparse)
-S, --sparse 有效率地處理稀疏檔案

覆寫控制:

-k, --keep-old-files don't replace existing files when extracting,
treat them as errors
--keep-directory-symlink preserve existing symlinks to directories when
extracting
--keep-newer-files
不要替換既有且比它們在封存中複本還新的檔案
--no-overwrite-dir 保留既有目錄的後設資料
--one-top-level[=目錄] create a subdirectory to avoid having loose
files extracted
--overwrite 解開時覆寫既有檔案
--overwrite-dir 解開時覆寫既有目錄的後設資料
(預設)
--recursive-unlink 在解開目錄之前先清空階層結構
--remove-files 在加入檔案至封存之後移除它們
--skip-old-files don't replace existing files when extracting,
silently skip over them
-U, --unlink-first 在解開並覆寫檔案之前先移除它
-W, --verify 嘗試在寫入之後驗證封存

選取輸出串流:

--ignore-command-error 忽略子行程的離開代碼
--no-ignore-command-error
將子行程的非零離開代碼視為錯誤
-O, --to-stdout 解開檔案到標準輸出
--to-command=命令 將解開的檔案管線引導到另外的程式

檔案屬性的處理:

--atime-preserve[=方法]
保留傾印檔案的存取時間,若非由讀取之後的回復時間(方法='replace';預設),就是藉由原本不設定時間
(方法='system')
--delay-directory-restore
延遲設定解開目錄的修改時間和權限,直到解開結束
--group=名稱 強制以 NAME 做為加入檔案的群組
--mode=變更 強制將 (符號) 模式 CHANGES
用於已加入檔案
--mtime=檔案的日期 將加入檔案的 mtime 設定為
DATE-OR-FILE
-m, --touch 不要解開檔案的修改時間
--no-delay-directory-restore
取消 --delay-directory-restore 選項的效果
--no-same-owner 以您自己擁有的屬性來抽出檔案
(預設用於一般使用者)
--no-same-permissions 從封存解開權限時套用使用者 umask
(預設用於一般使用者)
--numeric-owner 總是使用數字做為使用者/群組名稱
--owner=名稱 強制以 NAME 做為加入檔案的擁有者
-p, --preserve-permissions, --same-permissions
解開檔案權限相關資訊
(預設用於超級使用者)
--preserve 等同於指定 -p 與 -s
--same-owner
嘗試以與存在於封存中的相同擁有屬性來抽出檔案
(預設用於系統管理者)
-s, --preserve-order, --same-order
member arguments are listed in the same order as
the files in the archive
--sort=ORDER directory sorting order: none (default), name or
inode

Handling of extended file attributes:

--acls Enable the POSIX ACLs support
--no-acls Disable the POSIX ACLs support
--no-selinux Disable the SELinux context support
--no-xattrs Disable extended attributes support
--selinux Enable the SELinux context support
--xattrs Enable extended attributes support
--xattrs-exclude=MASK specify the exclude pattern for xattr keys
--xattrs-include=MASK specify the include pattern for xattr keys

裝置選擇與切換:

-f, --file=封存 使用 ARCHIVE 檔案或 ARCHIVE 裝置
--force-local
即使具有冒號,封存檔案仍位於本地端
-F, --info-script=名稱, --new-volume-script=名稱
在每卷磁帶末端執行命令稿 (意指 -M)
-L, --tape-length=數目 在寫入 NUMBER x 1024
位元組之後更換磁帶
-M, --multi-volume 建立/列表/解開 多重卷冊的封存
--rmt-command=命令 使用給定的 rmt COMMAND 以代替 rmt
--rsh-command=命令 使用遠端 COMMAND 以代替 rsh
--volno-file=檔案 使用/更新 FILE 中的卷冊號碼

裝置分區:

-b, --blocking-factor=區塊 每筆記錄含有 BLOCKS x 512 位元組
-B, --read-full-records 讀取時重新分區 (用於 4.2BSD 管線)
-i, --ignore-zeros 忽略封存中零值的區塊 (意指 EOF)
--record-size=數目 每筆記錄 SIZE 位元組,為 512 的倍數

封存格式選擇:

-H, --format=格式 以給定格式建立封存

符合下列任一 FORMAT:

gnu GNU tar 1.13.x 格式
oldgnu tar <= 1.12 之 GNU 格式
pax POSIX 1003.1-2001 (pax) 格式
posix 等同 pax
ustar POSIX 1003.1-1988 (ustar) 格式
v7 舊式 V7 tar 格式

--old-archive, --portability
等同 --format=v7
--pax-option=關鍵字[[:]=值][,關鍵字[[:]=值]…]
控制 pax 的關鍵字
--posix 等同 --format=posix
-V, --label=文字 以卷冊名稱 NAME
來建立封存。在列表/解開時,使用
TEXT 做為卷冊名稱的萬用比對胚騰

壓縮選項:

-a, --auto-compress 利用封存字尾決定壓縮程式
-I, --use-compress-program=程式
以 PROG 過濾處理 (必須接受 -d)
-j, --bzip2 將封存透過 bzip2 篩選
-J, --xz 將封存透過 xz 篩選
--lzip 將封存透過 lzip 篩選
--lzma 將封存透過 xz --format=lzma 篩選
--lzop 將封存透過 xz 篩選
--no-auto-compress 不利用封存字尾決定壓縮程式
-z, --gzip, --gunzip, --ungzip 將封存透過 gzip 篩選
-Z, --compress, --uncompress 將封存透過 compress 篩選

本機檔案選擇:

--add-file=檔案 將給定的 FILE 加入封存
(如果它的名稱以減號開始時就很有用)

--backup[=控制] 移除之前先備份,選擇版本 CONTROL
-C, --directory=目錄 更改至目錄 DIR
--exclude=胚騰 排除給定胚騰的檔案
--exclude-backups 排除備份和鎖定檔案
--exclude-caches 排除包含 CACHEDIR.TAG
的目錄內容,除了該標記檔案本身
--exclude-caches-all 排除包含 CACHEDIR.TAG 的目錄
--exclude-caches-under 排除包含 CACHEDIR.TAG
的目錄之下所有東西
--exclude-ignore=檔案 read exclude patterns for each directory from
FILE, if it exists
--exclude-ignore-recursive=檔案
read exclude patterns for each directory and its
subdirectories from FILE, if it exists
--exclude-tag=檔案 排除包含 FILE
的目錄內容,除了該檔案本身
--exclude-tag-all=檔案 排除包含 FILE 的目錄
--exclude-tag-under=檔案 排除包含 FILE
的目錄之下所有東西
--exclude-vcs 排除版本控制系統目錄
--exclude-vcs-ignores read exclude patterns from the VCS ignore files
-h, --dereference
跟隨符號連結;封存和傾印它們所指涉的檔案
--hard-dereference
跟隨硬式連結;封存和傾印它們所參考的檔案
-K, --starting-file=成員-名稱
begin at member MEMBER-NAME when reading the
archive
--newer-mtime=日期 只有當資料變更時才比較日期和時間
--no-null 停用先前 --null 選項的效果
--no-recursion 避免自動在目錄中遞降
--no-unquote do not unquote input file or member names
--null -T 讀取零值終結的名稱,停用 -C
-N, --newer=檔案的日期, --after-date=檔案的日期
只儲存比 DATE-OF-FILE 還新的檔案
--one-file-system 建立封存時保持在本地檔案系統中
-P, --absolute-names don't strip leading '/'s from file names
--recursion 遞迴進入目錄 (預設)
--suffix=字串 移除之前先備份並覆寫常用後置文字 (
~ 除非被環境變數 SIMPLE_BACKUP_SUFFIX
所蓋過)
-T, --files-from=檔案 從 FILE 中取得要解開或建立的名稱
--unquote unquote input file or member names (default)
-X, --exclude-from=檔案 排除 FILE 中所列出的胚騰

檔案名稱變換:

--strip-components=數目 從檔案名稱中截去以 NUMBER
為首的成分
--transform=表示式, --xform=表示式
利用 sed 將 EXPRESSION
替代為變換檔案名稱

檔案名稱吻合選項 (同時影響排除和包含胚騰同者):

--anchored 吻合檔案名稱開頭的胚騰
--ignore-case 忽略大小寫
--no-anchored patterns match after any '/' (default for
exclusion)
--no-ignore-case 大小寫需相符的吻合 (預設)
--no-wildcards 逐字進行吻合
--no-wildcards-match-slash wildcards do not match '/'
--wildcards use wildcards (default)
--wildcards-match-slash wildcards match '/' (default for exclusion)

富含資訊的輸出:

--checkpoint[=數目] 每幾項記錄顯示一次進度訊息 (預設
10)
--checkpoint-action=動作 於每個查核點執行 ACTION
--full-time 以完整精度印出檔案時間
--index-file=檔案 將詳細輸出送至 FILE
-l, --check-links
如果並非所有連結都被傾印則印出訊息
--no-quote-chars=字串 停用來自字串的引號字元
--quote-chars=字串 來自 STRING 的額外引號字元
--quoting-style=樣式
設定名稱引號樣式;參看下列的有效樣式值
-R, --block-number
每則訊息附帶顯示在封存中的區塊號碼
--show-defaults 顯示 tar 預設值
--show-omitted-dirs
當表列或解開時,列出每一個不符合搜尋條件的目錄
--show-snapshot-field-ranges
show valid ranges for snapshot-file fields
--show-transformed-names, --show-stored-names
顯示變換之後的檔案或封存名稱
--totals[=信號]
處理封存之後列印位元組總計;當此信號被投遞時,利用引數
-
列印位元組總計;允許的信號是:SIGHUP、SIGQUIT、SIGINT、SIGUSR1
和 SIGUSR2;不具 SIG
前綴的名稱也是可接受的
--utc 以 UTC 印出檔案修改時間
-v, --verbose 詳細列出處理過的檔案
--warning=關鍵字 警告控制
-w, --interactive, --confirmation
任何動作都要求確認

相容選項:

-o 當建立時,等同於
--old-archive。當解開時,等同於
--no-same-owner

其他選項:

-?, --help 給出這個使用方式列表
--restrict 停用某些潛在有害的選項
--usage 給出簡短的使用訊息
--version 印出程式版本

長選項的必須或可選用的引數也是相對應短選項的必須或可選用的引數。

The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control may be set with --backup or VERSION_CONTROL, values are:

none, off never make backups
t, numbered make numbered backups
nil, existing numbered if numbered backups exist, simple otherwise
never, simple always make simple backups

用於 --quoting-style 的有效引數選項是:

literal
shell
shell-always
c
c-maybe
escape
locale
clocale

*這個* tar 預設為:
--format=gnu -f- -b20 --quoting-style=escape --rmt-command=/etc/rmt
--rsh-command=/usr/bin/ssh

請向 <bug-tar@gnu.org> 回報錯誤。





TOP


[ add comment ]   |  permalink  |  print article  |   ( 4 / 1 )

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |