tar: -c: 建立壓縮檔案 -x:解壓 -t:查看內(nèi)容 -r:向壓縮歸檔文件末尾追加文件 -u:更新原壓縮包中的文件 這五個(gè)是獨(dú)立的命令,壓縮解壓都要用到其中一個(gè),可以和別的命令連用但只能用其中一個(gè)。下面的參數(shù)是根據(jù)需要在壓縮或解壓檔案時(shí)可選的。 -z:有g(shù)zip屬性的 -j:有bz2屬性的 -Z:有compress屬性的 -v:顯示所有過程 -O:將文件解開到標(biāo)準(zhǔn)輸出 下面的參數(shù)-f是必須的 -f: 使用檔案名字,切記,這個(gè)參數(shù)是最后一個(gè)參數(shù),后面只能接檔案名。 # tar -cf all.tar *.jpg 這條命令是將所有.jpg的文件打成一個(gè)名為all.tar的包。-c是表示產(chǎn)生新的包,-f指定包的文件名。 # tar -rf all.tar *.gif 這條命令是將所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。 # tar -uf all.tar logo.gif 這條命令是更新原來tar包all.tar中l(wèi)ogo.gif文件,-u是表示更新文件的意思。 # tar -tf all.tar 這條命令是列出all.tar包中所有文件,-t是列出文件的意思 # tar -xf all.tar 這條命令是解出all.tar包中所有文件,-t是解開的意思 壓縮: tar -cvf jpg.tar *.jpg //將目錄里所有jpg文件打包成tar.jpg tar -czf jpg.tar.gz *.jpg //將目錄里所有jpg文件打包成jpg.tar后,并且將其用gzip壓縮,生成一個(gè)gzip壓縮過的包,命名為jpg.tar.gz tar -cjf jpg.tar.bz2 *.jpg //將目錄里所有jpg文件打包成jpg.tar后,并且將其用bzip2壓縮,生成一個(gè)bzip2壓縮過的包,命名為jpg.tar.bz2 tar -cZf jpg.tar.Z *.jpg //將目錄里所有jpg文件打包成jpg.tar后,并且將其用compress壓縮,生成一個(gè)umcompress壓縮過的包,命名為jpg.tar.Z rar a jpg.rar *.jpg //rar格式的壓縮,需要先下載rar for linux zip jpg.zip *.jpg //zip格式的壓縮,需要先下載zip for linux 解壓: tar -xvf file.tar //解壓 tar包 tar -xzvf file.tar.gz //解壓tar.gz tar -xjvf file.tar.bz2 //解壓 tar.bz2 tar -xZvf file.tar.Z //解壓tar.Z unrar e file.rar //解壓rar unzip file.zip //解壓zip 總結(jié): 1、*.tar 用 tar -xvf 解壓 2、*.gz 用 gzip -d或者gunzip 解壓 3、*.tar.gz和*.tgz 用 tar -xzf 解壓 4、*.bz2 用 bzip2 -d或者用bunzip2 解壓 5、*.tar.bz2用tar -xjf 解壓 6、*.Z 用 uncompress 解壓 7、*.tar.Z 用tar -xZf 解壓 8、*.rar 用 unrar e解壓 9、*.zip 用 unzip 解壓 解壓jdk到指定文件夾: tar -xzvf jdk-8u131-linux-x64.tar.gz -C /usr/local/java
root@ubuntu:~# tar --help 用法: tar [選項(xiàng)...] [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 創(chuàng)建一個(gè)新歸檔 -d, --diff, --compare 找出歸檔和文件系統(tǒng)的差異 --delete 從歸檔(非磁帶!)中刪除 -r, --append 追加文件至歸檔結(jié)尾 -t, --list 列出歸檔內(nèi)容 --test-label 測試歸檔卷標(biāo)并退出 -u, --update 僅追加比歸檔中副本更新的文件 -x, --extract, --get 從歸檔中解出文件操作修飾符: --check-device 當(dāng)創(chuàng)建增量歸檔時(shí)檢查設(shè)備號(hào)(默認(rèn)) -g, --listed-incremental=FILE 處理新式的 GNU 格式的增量備份 -G, --incremental 處理老式的 GNU 格式的增量備份 --ignore-failed-read 當(dāng)遇上不可讀文件時(shí)不要以非零值退出 --level=NUMBER 所創(chuàng)建的增量列表歸檔的輸出級(jí)別 -n, --seek 歸檔可檢索 --no-check-device 當(dāng)創(chuàng)建增量歸檔時(shí)不要檢查設(shè)備號(hào) --no-seek 歸檔不可檢索 --occurrence[=NUMBER] 僅處理歸檔中每個(gè)文件的第 NUMBER 個(gè)事件;僅當(dāng)與以下子命令 --delete, --diff, --extract 或是 --list 中的一個(gè)聯(lián)合使用時(shí),此選項(xiàng)才有效。而且不管文件列表是以命令行形式給出或是通過 -T 選項(xiàng)指定的;NUMBER 值默認(rèn)為 1 --sparse-version=MAJOR[.MINOR] 設(shè)置所用的離散格式版本(隱含 --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 保留已存在目錄的元數(shù)據(jù) --one-top-level[=DIR] create a subdirectory to avoid having loose files extracted --overwrite 解壓時(shí)重寫存在的文件 --overwrite-dir 解壓時(shí)重寫已存在目錄的元數(shù)據(jù)(默認(rèn)) --recursive-unlink 解壓目錄之前先清除目錄層次 --remove-files 在添加文件至歸檔后刪除它們 --skip-old-files don‘t replace existing files when extracting, silently skip over them -U, --unlink-first 在解壓要重寫的文件之前先刪除它們 -W, --verify 在寫入以后嘗試校驗(yàn)歸檔選擇輸出流: --ignore-command-error 忽略子進(jìn)程的退出代碼 --no-ignore-command-error 將子進(jìn)程的非零退出代碼認(rèn)為發(fā)生錯(cuò)誤 -O, --to-stdout 解壓文件至標(biāo)準(zhǔn)輸出 --to-command=COMMAND 將解壓的文件通過管道傳送至另一個(gè)程序操作文件屬性: --atime-preserve[=METHOD] 在輸出的文件上保留訪問時(shí)間,要么通過在讀取(默認(rèn) METHOD=‘replace’)后還原時(shí)間,要不就不要在第一次(METHOD=‘system’)設(shè)置時(shí)間 --clamp-mtime only set time when the file is more recent than what was given with --mtime --delay-directory-restore 直到解壓結(jié)束才設(shè)置修改時(shí)間和所解目錄的權(quán)限 --group=名稱 強(qiáng)制將 NAME 作為所添加的文件的組所有者 --mode=CHANGES 強(qiáng)制將所添加的文件(符號(hào))更改為權(quán)限 CHANGES --mtime=DATE-OR-FILE 從 DATE-OR-FILE 中為添加的文件設(shè)置 mtime -m, --touch 不要解壓文件的修改時(shí)間 --no-delay-directory-restore 取消 --delay-directory-restore 選項(xiàng)的效果 --no-same-owner 將文件解壓為您所有(普通用戶默認(rèn)此項(xiàng)) --no-same-permissions 從歸檔中解壓權(quán)限時(shí)使用用戶的掩碼位(默認(rèn)為普通用戶服務(wù)) --numeric-owner 總是以數(shù)字代表用戶/組的名稱 --owner=名稱 強(qiáng)制將 NAME 作為所添加的文件的所有者 -p, --preserve-permissions, --same-permissions 解壓文件權(quán)限信息(默認(rèn)只為超級(jí)用戶服務(wù)) --preserve 與 -p 和 -s 一樣 --same-owner 嘗試解壓時(shí)保持所有者關(guān)系一致(超級(jí)用戶默認(rèn)此項(xiàng)) -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 設(shè)備選擇和切換: -f, --file=ARCHIVE 使用歸檔文件或 ARCHIVE 設(shè)備 --force-local 即使歸檔文件存在副本還是把它認(rèn)為是本地歸檔 -F, --info-script=名稱, --new-volume-script=名稱在每卷磁帶最后運(yùn)行腳本(隱含 -M) -L, --tape-length=NUMBER 寫入 NUMBER × 1024 字節(jié)后更換磁帶 -M, --multi-volume 創(chuàng)建/列出/解壓多卷歸檔文件 --rmt-command=COMMAND 使用指定的 rmt COMMAND 代替 rmt --rsh-command=COMMAND 使用遠(yuǎn)程 COMMAND 代替 rsh --volno-file=FILE 使用/更新 FILE 中的卷數(shù)設(shè)備分塊: -b, --blocking-factor=BLOCKS 每個(gè)記錄 BLOCKS x 512 字節(jié) -B, --read-full-records 讀取時(shí)重新分塊(只對(duì) 4.2BSD 管道有效) -i, --ignore-zeros 忽略歸檔中的零字節(jié)塊(即文件結(jié)尾) --record-size=NUMBER 每個(gè)記錄的字節(jié)數(shù) NUMBER,乘以 512 選擇歸檔格式: -H, --format=FORMAT 創(chuàng)建指定格式的歸檔 FORMAT 是以下格式中的一種: gnu GNU tar 1.13.x 格式 oldgnu GNU 格式 as per tar <= 1.12 pax POSIX 1003.1-2001 (pax) 格式 posix 等同于 pax ustar POSIX 1003.1-1988 (ustar) 格式 v7 old V7 tar 格式 --old-archive, --portability 等同于 --format=v7 --pax-option=關(guān)鍵字[[:]=值][,關(guān)鍵字[[:]=值]]... 控制 pax 關(guān)鍵字 --posix 等同于 --format=posix -V, --label=TEXT 創(chuàng)建帶有卷名 TEXT 的歸檔;在列出/解壓時(shí),使用 TEXT 作為卷名的模式串壓縮選項(xiàng): -a, --auto-compress 使用歸檔后綴名來決定壓縮程序 -I, --use-compress-program=PROG 通過 PROG 過濾(必須是能接受 -d 選項(xiàng)的程序) -j, --bzip2 通過 bzip2 過濾歸檔 -J, --xz 通過 xz 過濾歸檔 --lzip 通過 lzip 過濾歸檔 --lzma 通過 xz 過濾歸檔 --lzop 通過 xz 過濾歸檔 --no-auto-compress 不使用歸檔后綴名來決定壓縮程序 -z, --gzip, --gunzip, --ungzip 通過 gzip 過濾歸檔 -Z, --compress, --uncompress 通過 compress 過濾歸檔本地文件選擇: --add-file=FILE 添加指定的 FILE 至歸檔(如果名字以 - 開始會(huì)很有用的) --backup[=CONTROL] 在刪除前備份,選擇 CONTROL 版本 -C, --directory=DIR 改變至目錄 DIR --exclude=PATTERN 排除以 PATTERN 指定的文件 --exclude-backups 排除備份和鎖文件 --exclude-caches 除標(biāo)識(shí)文件本身外,排除包含 CACHEDIR.TAG 的目錄中的內(nèi)容 --exclude-caches-all 排除包含 CACHEDIR.TAG 的目錄 --exclude-caches-under 排除包含 CACHEDIR.TAG 的目錄中所有內(nèi)容 --exclude-ignore=FILE read exclude patterns for each directory from FILE, if it exists --exclude-ignore-recursive=FILE read exclude patterns for each directory and its subdirectories from FILE, if it exists --exclude-tag=FILE 除 FILE 自身外,排除包含 FILE 的目錄中的內(nèi)容 --exclude-tag-all=FILE 排除包含 FILE 的目錄 --exclude-tag-under=FILE 排除包含 FILE 的目錄中的所有內(nèi)容 --exclude-vcs 排除版本控制系統(tǒng)目錄 --exclude-vcs-ignores read exclude patterns from the VCS ignore files -h, --dereference 跟蹤符號(hào)鏈接;將它們所指向的文件歸檔并輸出 --hard-dereference 跟蹤硬鏈接;將它們所指向的文件歸檔并輸出 -K, --starting-file=MEMBER-NAME begin at member MEMBER-NAME when reading the archive --newer-mtime=DATE 當(dāng)只有數(shù)據(jù)改變時(shí)比較數(shù)據(jù)和時(shí)間 --no-null 禁用上一次的效果 --null 選項(xiàng) --no-recursion 避免目錄中的自動(dòng)降級(jí) --no-unquote do not unquote input file or member names --null -T 讀取以空終止的名字,-C 禁用 -N, --newer=DATE-OR-FILE, --after-date=DATE-OR-FILE 只保存比 DATE-OR-FILE 更新的文件 --one-file-system 創(chuàng)建歸檔時(shí)保存在本地文件系統(tǒng)中 -P, --absolute-names don‘t strip leading ‘/‘s from file names --recursion 目錄遞歸(默認(rèn)) --suffix=STRING 在刪除前備份,除非被環(huán)境變量 SIMPLE_BACKUP_SUFFIX 覆蓋,否則覆蓋常用后綴(‘’) -T, --files-from=FILE 從 FILE 中獲取文件名來解壓或創(chuàng)建文件 --unquote unquote input file or member names (default) -X, --exclude-from=FILE 排除 FILE 中列出的模式串文件名變換: --strip-components=NUMBER 解壓時(shí)從文件名中清除 NUMBER 個(gè)引導(dǎo)部分 --transform=EXPRESSION, --xform=EXPRESSION 使用 sed 代替 EXPRESSION 來進(jìn)行文件名變換文件名匹配選項(xiàng)(同時(shí)影響排除和包括模式串): --anchored 模式串匹配文件名頭部 --ignore-case 忽略大小寫 --no-anchored patterns match after any ‘/‘ (default for exclusion) --no-ignore-case 匹配大小寫(默認(rèn)) --no-wildcards 逐字匹配字符串 --no-wildcards-match-slash wildcards do not match ‘/‘ --wildcards 使用通配符(默認(rèn)對(duì) exclusion ) --wildcards-match-slash wildcards match ‘/‘ (default for exclusion) 提示性輸出: --checkpoint[=NUMBER] 每隔 NUMBER 個(gè)記錄顯示進(jìn)度信息(默認(rèn)為 10 個(gè)) --checkpoint-action=ACTION 在每個(gè)檢查點(diǎn)上執(zhí)行 ACTION --full-time 按文件原本時(shí)間格式打印 --index-file=FILE 將詳細(xì)輸出發(fā)送至 FILE -l, --check-links 只要不是所有鏈接都被輸出就打印信息 --no-quote-chars=STRING 禁用來自 STRING 的字符引用 --quote-chars=STRING 來自 STRING 的額外的引用字符 --quoting-style=STYLE 設(shè)置名稱引用風(fēng)格;有效的 STYLE 值請參閱以下說明 -R, --block-number 每個(gè)信息都顯示歸檔內(nèi)的塊數(shù) --show-defaults 顯示 tar 默認(rèn)選項(xiàng) --show-omitted-dirs 列表或解壓時(shí),列出每個(gè)不匹配查找標(biāo)準(zhǔn)的目錄 --show-snapshot-field-ranges show valid ranges for snapshot-file fields --show-transformed-names, --show-stored-names 顯示變換后的文件名或歸檔名 --totals[=SIGNAL] 處理歸檔后打印出總字節(jié)數(shù);當(dāng)此 SIGNAL 被觸發(fā)時(shí)帶參數(shù) - 打印總字節(jié)數(shù);允許的信號(hào)為: SIGHUP,SIGQUIT,SIGINT,SIGUSR1 和 SIGUSR2;同時(shí)也接受不帶 SIG 前綴的信號(hào)名稱 --utc 以 UTC 格式打印文件修改時(shí)間 -v, --verbose 詳細(xì)地列出處理的文件 --warning=KEYWORD 警告控制: -w, --interactive, --confirmation 每次操作都要求確認(rèn)兼容性選項(xiàng): -o 創(chuàng)建歸檔時(shí),相當(dāng)于 --old-archive;展開歸檔時(shí),相當(dāng)于 --no-same-owner 其它選項(xiàng): -?, --help 顯示此幫助列表 --restrict 禁用某些潛在的有危險(xiǎn)的選項(xiàng) --usage 顯示簡短的用法說明 --version 打印程序版本長選項(xiàng)和相應(yīng)短選項(xiàng)具有相同的強(qiáng)制參數(shù)或可選參數(shù)。 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 選項(xiàng)的有效參數(shù)為: literal shell shell-always c c-maybe escape locale clocale 此 tar 默認(rèn)為: --format=gnu -f- -b20 --quoting-style=escape --rmt-command=/usr/lib/tar/rmt --rsh-command=/usr/bin/rsh 將錯(cuò)誤報(bào)告發(fā)送到 <bug-tar@gnu.org>。 |
免責(zé)聲明:本站部分文章和圖片均來自用戶投稿和網(wǎng)絡(luò)收集,旨在傳播知識(shí),文章和圖片版權(quán)歸原作者及原出處所有,僅供學(xué)習(xí)與參考,請勿用于商業(yè)用途,如果損害了您的權(quán)利,請聯(lián)系我們及時(shí)修正或刪除。謝謝!
始終以前瞻性的眼光聚焦站長、創(chuàng)業(yè)、互聯(lián)網(wǎng)等領(lǐng)域,為您提供最新最全的互聯(lián)網(wǎng)資訊,幫助站長轉(zhuǎn)型升級(jí),為互聯(lián)網(wǎng)創(chuàng)業(yè)者提供更加優(yōu)質(zhì)的創(chuàng)業(yè)信息和品牌營銷服務(wù),與站長一起進(jìn)步!讓互聯(lián)網(wǎng)創(chuàng)業(yè)者不再孤獨(dú)!
掃一掃,關(guān)注站長網(wǎng)微信