Linux打包和壓縮——管理打包和壓縮的命令

Linux打包和壓縮——管理打包和壓縮的命令

摘要:本文主要學習了Linux的打包命令和壓縮命令。學習

tar命令

tar命令能夠用來進行打包和解打包,壓縮和解壓縮。測試

基本語法

打包和壓縮的語法:spa

1 [root@localhost ~]# tar [選項] 源文件或目錄

解打包和解壓縮的語法:code

1 [root@localhost ~]# tar [選項] 壓縮包

選項說明

打包和壓縮的選項:blog

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

解打包和解壓縮的選項:遞歸

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

使用舉例

打包和壓縮:ip

 1 [root@localhost home]# ls
 2 hello  hello-hard  hello-soft  test  test-soft
 3 [root@localhost home]# tar -cvf hello.tar hello hello-hard hello-soft 
 4 hello
 5 hello-hard
 6 hello-soft
 7 [root@localhost home]# ls
 8 hello  hello-hard  hello-soft  hello.tar  test  test-soft
 9 [root@localhost home]# tar -zcvf test.tar.gz test test-soft
10 test/
11 test-soft
12 [root@localhost home]# ls
13 hello  hello-hard  hello-soft  hello.tar  test  test-soft  test.tar.gz
14 [root@localhost home]# 

解打包和解壓縮:class

 1 [root@localhost home]# ls
 2 hello.tar  test.tar.gz
 3 [root@localhost home]# tar -xvf hello.tar 
 4 hello
 5 hello-hard
 6 hello-soft
 7 [root@localhost home]# ls
 8 hello  hello-hard  hello-soft  hello.tar  test.tar.gz
 9 [root@localhost home]# tar -zxvf test.tar.gz 
10 test/
11 test-soft
12 [root@localhost home]# ls
13 hello  hello-hard  hello-soft  hello.tar  test  test-soft  test.tar.gz
14 [root@localhost home]# 

zip命令

zip命令相似於Windows系統中的winzip壓縮程序。test

基本語法

1 [root@localhost ~]# zip [選項] 壓縮包名 源文件或源目錄列表

選項說明

1 -r:遞歸壓縮目錄,及將指定目錄下的全部文件以及子目錄所有壓縮。
2 -m:將文件壓縮以後,刪除原始文件,至關於把文件移到壓縮文件中。
3 -v:顯示詳細的壓縮過程信息。
4 -q:在壓縮的時候不顯示命令的執行過程。
5 -n:n表示數字,壓縮級別是從1~9的數字,-1表明壓縮速度更快,-9表明壓縮效果更好。
6 -u:更新壓縮文件,即往壓縮文件中添加新文件。

使用舉例

 1 [root@localhost home]# ls
 2 hello  hello-hard  hello-soft  test  test-soft
 3 [root@localhost home]# zip hello.zip hello hello-hard 
 4   adding: hello (deflated 99%)
 5   adding: hello-hard (deflated 99%)
 6 [root@localhost home]# ls
 7 hello  hello-hard  hello-soft  hello.zip  test  test-soft
 8 [root@localhost home]# zip test.zip test test-soft
 9   adding: test/ (stored 0%)
10   adding: test-soft/ (stored 0%)
11 [root@localhost home]# ls
12 hello  hello-hard  hello-soft  hello.zip  test  test-soft  test.zip
13 [root@localhost home]#

unzip命令

unzip命令能夠查看和解壓縮zip文件。打包

基本語法

1 [root@localhost ~]# unzip [選項] 壓縮包名

選項說明

1 -d name:name是目錄名,將壓縮文件解壓到指定目錄下。
2 -n:解壓時並不覆蓋已經存在的文件。
3 -o:解壓時覆蓋已經存在的文件,而且無需用戶確認。
4 -v:查看壓縮文件的詳細信息,包括壓縮文件中包含的文件大小、文件名以及壓縮比等,但並不作解壓操做。
5 -t:測試壓縮文件有無損壞,但並不解壓。
6 -x name:name是文件列表,解壓文件,但不包含文件列表中指定的文件。

使用舉例

 1 [root@localhost home]# ls
 2 hello.zip  test.zip
 3 [root@localhost home]# unzip -v hello.zip 
 4 Archive:  hello.zip
 5  Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
 6 --------  ------  ------- ---- ---------- ----- --------  ----
 7    10240  Defl:N       99  99% 07-11-2019 01:28 dda39bf9  hello
 8    10240  Defl:N       99  99% 07-11-2019 01:28 dda39bf9  hello-hard
 9 --------          -------  ---                            -------
10    20480              198  99%                            2 files
11 [root@localhost home]# unzip hello.zip 
12 Archive:  hello.zip
13   inflating: hello                   
14   inflating: hello-hard              
15 [root@localhost home]# ls
16 hello  hello-hard  hello.zip  test.zip
17 [root@localhost home]# unzip -d zip test.zip 
18 Archive:  test.zip
19    creating: zip/test/
20    creating: zip/test-soft/
21 [root@localhost home]# ls
22 hello  hello-hard  hello.zip  test.zip  zip
23 [root@localhost home]# ls zip
24 test  test-soft
25 [root@localhost home]#
相關文章
相關標籤/搜索