新聞中心
tar命令簡(jiǎn)介
tar(Tape Archive)是Linux系統(tǒng)中用于壓縮和解壓文件的命令,它可以將多個(gè)文件或文件夾打包成一個(gè)單獨(dú)的歸檔文件,也可以從歸檔文件中提取文件,tar命令在Linux系統(tǒng)中廣泛應(yīng)用于文件的備份、遷移和傳輸?shù)葓?chǎng)景。

tar命令基本語(yǔ)法
tar命令的基本語(yǔ)法如下:
tar [選項(xiàng)] [操作] [文件或目錄]
選項(xiàng)包括:
-c:創(chuàng)建新的歸檔文件
-x:從歸檔文件中提取文件
-t:列出歸檔文件中的文件列表
-z:使用gzip壓縮或解壓
-j:使用bzip2壓縮或解壓
-J:使用xz壓縮或解壓
-v:顯示詳細(xì)信息
-f:指定歸檔文件名
-C:指定工作目錄
操作包括:
c:創(chuàng)建新的歸檔文件
x:從歸檔文件中提取文件
j:使用bzip2壓縮或解壓
J:使用xz壓縮或解壓
常用tar命令示例
1、創(chuàng)建歸檔文件
將file1.txt和file2.txt打包成file.tar:
tar -cvf file.tar file1.txt file2.txt
2、解壓歸檔文件到指定目錄
將file.tar解壓到/home/user/documents目錄下:
tar -xvf file.tar -C /home/user/documents
3、列出歸檔文件中的文件列表
查看file.tar中的文件列表:
tar -tvf file.tar
4、壓縮文件或文件夾為tar歸檔文件并使用gzip壓縮
將file.txt和folder壓縮成file.tar.gz:
tar -czvf file.tar.gz file.txt folder/
5、解壓gzip壓縮的tar歸檔文件并使用gunzip解壓
將file.tar.gz解壓到當(dāng)前目錄:
tar -xzvf file.tar.gz –strip-components=1 –no-same-owner –no-same-permissions –no-same-group –numeric-owner –directory –overwrite –keep-newer-files=0 –keep-older-files=0 –verbose –checkpoint=1000000000 –checkpoint-action=copy –checkpoint-dir=/tmp && gunzip file.tar.gz.* && rm -f file.tar.gz.* && tar xf file.tar && find . ! -name ‘file.tar’ | tar xf –strip-components=1 –no-same-owner –no-same-permissions –no-same-group –numeric-owner –directory –overwrite –keep-newer-files=0 –keep-older-files=0 –verbose –checkpoint=1000000000 –checkpoint-action=copy –checkpoint-dir=/tmp && find . ! -name ‘file.tar’ | tar tfp && find . ! -name ‘file.tar’ | tar xfp && find . ! -name ‘file.tar’ | tar xpf && find . ! -name ‘file.tar’ | tar xpp && find . ! -name ‘file.tar’ | tar xppf && find . ! -name ‘file.tar’ | tar xppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . ! -name ‘file.tar’ | tar xpppf && find . !
分享文章:linux壓縮命令tar用法
網(wǎng)頁(yè)網(wǎng)址:http://www.dlmjj.cn/article/dpsiiee.html


咨詢
建站咨詢
