Linux打包命令


tar命令可以用來進行打包和解打包,壓縮和解壓縮

基本語法:

打包和壓縮的語法:

tar [選項] 源文件或目錄

解打包和解壓縮的語法:

tar [選項] 壓縮包

選項說明:

打包與壓縮的選項

1 -c:將多個文件或目錄進行打包。
2 -v:顯示打包文件的過程。
3 -f 文件名:指定打包的文件名。
4 -z:壓縮和解壓縮.tar.gz格式。
5 -j:壓縮和解壓縮.tar.bz2格式。

使用舉例:

打包為tar格式的文件

 [root@localhost home]# tar -cvf hello.tar hello hello-hard hello-soft 
 hello
 hello-hard
 hello-soft
 [root@localhost home]# ls
 hello  hello-hard  hello-soft  hello.tar  test  test-soft
 [root@localhost home]# 

壓縮為tar.gz格式的文件

 [root@localhost home]# tar -zcvf test.tar.gz test test-soft
 test/
 test-soft
 [root@localhost home]# ls
 hello  hello-hard  hello-soft  hello.tar  test  test-soft  test.tar.gz
 [root@localhost home]# 

 

解打包和解壓縮的選項

1 -x:對tar包做解打包操作。
2 -v:顯示解打包的過程。
3 -f 文件名:指定要解壓的文件名。
4 -z:壓縮和解壓縮.tar.gz格式。
5 -j:壓縮和解壓縮.tar.bz2格式。
6 -t:只查看包中有哪些文件或目錄,不做解打包操作。
7 -C 目錄名:指定解打包位置。

舉例說明:

解打包tar格式的文件

[root@localhost home]# tar -xvf hello.tar
hello
hello-hard
hello-soft
[root@localhost home]# ls
hello  hello-hard  hello-soft  hello.tar  test.tar.gz
[root@localhost home]#

解壓縮tar.gz格式的文件

[root@localhost home]# tar -zxvf test.tar.gz 
 test/
 test-soft
[root@localhost home]# ls
 hello  hello-hard  hello-soft  hello.tar  test  test-soft  test.tar.gz
[root@localhost home]# 

查看tar格式的文件內容

[root@localhost home]# tar -tvf hello.tar
 -rw-r--r-- root/root     10240 2019-07-11 01:28 hello
 hrw-r--r-- root/root         0 2019-07-11 01:28 hello-hard 連接到 hello
 lrwxrwxrwx root/root         0 2019-07-11 03:56 hello-soft -> hello
[root@localhost home]# 

查看tar.gz格式的文件內容

[root@localhost home]# tar -ztvf test.tar.gz 
drwxr-xr-x root/root         0 2019-07-11 01:14 test/
drwxr-xr-x root/root         0 2019-07-11 01:14 test-soft/
[root@localhost home]# 

 


免責聲明!

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



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