linux - tar命令簡單使用


tar

新建一個tar文檔

touch file1
touch file2
mkdir dir1
touch dir1/file3

# 普通tar文檔
tar -cf tar-file.tar file1 file2 dir1
# 壓縮的tar文檔(使用gnuzip算法)
tar -czf tgz-file.tgz file1 file2 dir1

** tgz格式通常也寫作tar.gz **

查看tar文檔內容

# 對於壓縮的tar文檔,也使用相同的命令
mint@lenovo ~/temp $ tar -tf tar-file.tar
file1
file2
dir1/
dir1/file3/
mint@lenovo ~/temp $ tar -tf tgz-file.tgz 
file1
file2
dir1/
dir1/file3

解壓tar文檔

解壓到當前工作路徑

# 未壓縮
tar -xf tar-file.tar
# 使用gnuzip算法進行壓縮的tar文檔
tar -xzf tgz-file.tar

解壓到指定目錄

# 未進行壓縮的tar文檔
tar -xf tar-file.tar -C /path/to/destination
# 使用gunzip算法壓縮的tar文檔
tar -xzf tgz-file.tgz -C /path/to/destination

示例

mint@lenovo ~/temp $ mkdir ex
mint@lenovo ~/temp $ tar -xf tar-file.tar -C ex/
mint@lenovo ~/temp $ cd ex/
mint@lenovo ~/temp/ex $ ls
dir1  file1  file2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM