tft每日頭條

 > 生活

 > linux解壓zip命令

linux解壓zip命令

生活 更新时间:2024-09-04 16:27:04

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)1

linux啟動界面

目錄

1.文件和目錄操作命令

2.用戶和用戶組操作命令

3.vim編輯器操作命令

4.打包和解壓操作命令

5.系統操作命令

這是總的目錄的,軟件測試人員需要掌握的Linux命令會分成多個章節來寫。

gzip 壓縮

格式:gzip 文件名

1.壓縮文件

[root@localhost test]# gzip services

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)2

2.對.gz文件使用gzip -d 解壓

[root@localhost test]# gzip services

[root@localhost test]# ls -lh services.gz

-rwxr-xr-x. 1 root root 125K Apr 14 17:55 services.gz

[root@localhost test]# gzip -d services.gz

[root@localhost test]# ls -hl services

-rwxr-xr-x. 1 root root 626K Apr 14 17:55 services

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)3

gzip壓縮工具解壓文件,gzip工具壓縮率非常高,所以使用也非常頻繁

tar 命令

打包和壓縮:

打包是指将一大堆文件或目錄變成一個總的文件

壓縮則是将一個大的文件通過一些壓縮算法變成一個小文件

這是二個步驟,是分開的

-c, --create 創建一個新歸檔

-x, --extract, --get 從歸檔中解出文件

-f, --file=ARCHIVE 使用歸檔文件或 ARCHIVE 設備

--force-local

即使歸檔文件存在副本還是把它認為是本地歸檔

-v, --verbose 詳細地列出處理的文件

-z, --gzip, --gunzip, --ungzip 通過 gzip 過濾歸檔

0.歸檔文件,并創建一個新的歸檔文件

将123233和yum.conf打包在一起

[root@localhost test]# tar -cf 12.tar 123233 yum.conf

變化:

1.文件大小沒變

[root@localhost test]# ls -hl 123233 12.tar yum.conf

-rw-r--r--. 1 501 test 9 4月 12 17:21 123233

-rw-r--r--. 1 root root 10K 4月 17 20:17 12.tar

-rwxrw-r--. 1 root root 969 4月 12 16:40 yum.conf

2.将二個文件生成一個.tar的文件

tar:在window來說就是将多個文件放到一個文件夾

3.将一個tar文件打開

[root@localhost test12]# tar -xvf 12.tar

4.在打包的同時并壓縮--- -czvf(經常用)

[root@localhost test12]# tar -czvf qq.tar.gz 123233 yum.conf

-rw-r--r--. 1 root root 10240 4月 17 20:23 12.tar

-rw-r--r--. 1 root root 757 4月 17 20:30 qq.tar.gz

以上二個文件内容相同,第一個文件是将多個文件隻 是打包在一起,第二個文件是将多個文件打包的同時并壓縮

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)4

5.解包并解壓

[root@localhost test12]# tar -xzvf q.tar.gz

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)5

tar命令打包并壓縮:原文件沒有被删除,而是生成一個新的.tar.gz

解壓的時候也是将.tar.gz裡的文件被釋放出來,如果有相同的文件名被覆蓋

打包壓縮:tar -czvf 新文件名.tar.gz 文件1 文件2 ... 目錄1 目錄2...

解包解壓:tar -xzvf 解包解壓的文件名

6.将某個目錄所有的文件和目錄都打包壓縮

[root@localhost test12]# tar -czvf test12.tar.gz *

zip 對文件或目錄壓縮

1.壓縮文件

[root@localhost test]# zip q.zip 123233 yum.conf

對比gzip和zip壓縮後的文件大小:

-rw-r--r--. 1 root root 757 4月 17 20:57 1.tar.gz

-rw-r--r--. 1 root root 891 4月 17 20:56 q.zip

可以得到gzip比zip壓縮率高

2.壓縮目錄 -r

[root@localhost test]# zip -r test.zip test12

原目錄與壓縮後的文件

drwxrwxrwx. 3 root root 4096 4月 17 20:44 test12

-rw-r--r--. 1 root root 516448 4月 17 21:00 test.zip

壓縮過程中原文件或原目錄不會被删除

unzip 解壓.zip文件

1.解壓

[root@localhost test]# unzip test.zip

2.将解壓的結果顯示在屏幕上 -c

[root@localhost test]# unzip -c q.zip

将文件的内容直接展示在屏幕上

3.-n 解壓時不要覆蓋原有的文件

使用-n時,原有文件存在

[root@localhost test]# unzip -n q.zip

Archive: q.zip

使用-n時,原有文件不存在

[root@localhost test]# unzip -n q.zip

unzip解壓後原來的.zip還存在

bzip2 壓縮文件

格式:bzip2 文件名

1.bzip2壓縮文件且原文件删除

[root@localhost test]# bzip2 yum.conf

并新生成了一個.bz2的文件

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)6

2.-k 壓縮文件的同時保留原文件

[root@localhost test]# bzip2 -k services

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)7

bunzip2 解壓

[root@localhost test]# bunzip2 123233.bz2

[root@localhost test]# ll

-rw-r--r--. 1 root root 9 4月 12 17:21 123233

生成一個新文件,原來的.bz2被删除了

linux解壓zip命令(快速高效學會Linux解壓縮命令tar)8

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关生活资讯推荐

热门生活资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved