牛客刷題——合併兩個有序陣列
阿新 • • 發佈:2021-02-06
技術標籤:linuxpythonjavashellubuntu
一、介紹
linux下一般使用的壓縮型別有以下幾種:
注意:widows和linux互通的壓縮包只有zip型別,linux不支援rar型別的,widows支援linux所有壓縮型別
二、基本命令
1、gzip(gz型別)
注意:gzip只能壓縮檔案,不能壓縮資料夾,壓縮資料夾,只會把資料夾下的檔案進行壓縮,壓縮好後會把原來的檔案刪除
'''
------命令格式-------
gzip options filename
------options引數--------
-a 使用ASCII文字模式。
-c 把壓縮後的檔案輸出到標準輸出裝置,不去更動原始檔案。
-d 解開壓縮檔案。
-f 強行壓縮檔案。不理會檔名稱或硬連線是否存在以及該檔案是否為符號連線。
-l 列出壓縮檔案的相關資訊。
-L 顯示版本與版權資訊。
-n 壓縮檔案時,不儲存原來的檔名稱及時間戳記。
-N 壓縮檔案時,儲存原來的檔名稱及時間戳記。
-q 不顯示警告資訊。
-r 遞迴處理,將指定目錄下的所有檔案及子目錄一併處理。
-S<壓縮字尾字串> 更改壓縮字尾字串。
-t 測試壓縮檔案是否正確無誤。
-v 顯示指令執行過程。
-V 顯示版本資訊。
-<壓縮效率> 壓縮效率是一個介於1-9的數值,預設值為"6",指定愈大的數值,壓縮效率就會愈高。
--best 此引數的效果和指定"-9"引數相同。
--fast 此引數的效果和指定"-1"引數相同。
'''
[ [email protected] /home/test]#gzip file #壓縮檔案file
[[email protected] /home/test]#ls
file1 file.gz
[[email protected] /home/test]#gzip -9 file #90%壓縮率壓縮檔案file
[[email protected] /home/test]#gzip -1 file1 #10%壓縮率壓縮檔案file
[[email protected] /home/test]#gzip -dv file1
file1.gz: 2.7% -- replaced with file1
[ [email protected] /home/test]#gzip -dv file
file.gz: 91.4% -- replaced with file
[[email protected] /home/test]#gzip -d file1.gz #解壓file1.gz
2、zip(zip型別)
zip支援檔案和資料夾打包壓縮。
# zip options 壓縮後文件名 壓縮檔案
'''
-A 調整可執行的自動解壓縮檔案。
-b<工作目錄> 指定暫時存放檔案的目錄。
-c 替每個被壓縮的檔案加上註釋。
-d 從壓縮檔案內刪除指定的檔案。
-D 壓縮檔案內不建立目錄名稱。
-f 更新現有的檔案。
-F 嘗試修復已損壞的壓縮檔案。
-g 將檔案壓縮後附加在既有的壓縮檔案之後,而非另行建立新的壓縮檔案。
-q 不顯示指令執行過程。
-r 遞迴處理,將指定目錄下的所有檔案和子目錄一併處理。
-T 檢查備份檔案內的每個檔案是否正確無誤。
-v 顯示指令執行過程或顯示版本資訊。
-z 替壓縮檔案加上註釋。
-<壓縮效率> 壓縮效率是一個介於1-9的數值。
'''
[ [email protected] /home]#zip test.zip test/ #壓縮zip檔案
adding: test/ (stored 0%)
[[email protected] /home]#unzip test.zip -d /home/test2/ #將zip檔案解壓到test2下
Archive: test.zip
creating: /home/test2/test/
[[email protected] /home]#unzip -l test.zip #不解壓,檢視壓縮包內檔案
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
0 01-11-2021 19:56 test/
--------- -------
0 1 file
3、tar
Linux下最常用的壓縮和解壓縮,支援檔案和目錄的壓縮歸檔
#語法:tar [-zjxcvfpP] filename
c #建立新的歸檔檔案
x #對歸檔檔案解包
t #列出歸檔檔案裡的檔案列表
v #輸出命令的歸檔或解包的過程
f #指定包檔名,多引數f寫最後
z #使用gzip壓縮歸檔後的檔案(.tar.gz)
j #使用bzip2壓縮歸檔後的檔案(.tar.bz2)
J #使用xz壓縮歸檔後的檔案(tar.xz)
C #指定解壓目錄位置
X #排除多個檔案(寫入需要排除的檔名稱)
h #打包軟連結
--hard-dereference #打包硬連結
--exclude #在打包的時候寫入需要排除檔案或目錄
#常用打包與壓縮組合
czf #打包tar.gz格式 常用
cjf #打包tar.bz格式 不怎麼用
cJf #打包tar.xz格式 不考慮
zxf #解壓tar.gz格式
jxf #解壓tar.bz格式
xf #自動選擇解壓模式
xvf #顯示解壓過程
tf #檢視壓縮包內容
(1)tar + gzip打包壓縮
#1、壓縮 tar czf 壓縮後名字 檔名
[[email protected] /home/nq]#tar czf test.tar.gz test/
[[email protected] /home/nq]#ls
test test.tar.gz
#2、解壓 tar zxf 解壓檔名
[[email protected] /home/nq]#tar zxf test.tar.gz
(2)tar +bzip2打包壓縮
#1、解壓命令:tar jxf 解壓檔名
[[email protected] /home/nq]#tar jxf test.tar.bz2
#2、壓縮命令:tar cjf 壓縮後名字 檔名
[[email protected] /home/nq]#tar cjf test.tar.bz2 test
[[email protected] /home/nq]#ls
test test.tar.bz2 test.tar.gz
(3)排除檔案壓縮和檢視壓縮內容
# 1、壓縮排除passwd檔案
[[email protected] /home/nq]#tar czf excu.tar.gz --exclude=test/passwd test/
# 2、檢視壓縮內容
[[email protected] /home/nq]#tar tf excu.tar.gz
test/
test/test2
test/proxy.conf
test/test.txt
test/test2.txt
test/proxy1
# 3、以檔案形式排除多個檔案,進行壓縮
[[email protected] /home/nq]#cat paichu.list
test/passwd
test/proxy.conf
test/proxy1
[[email protected] /home/nq]#tar czfX etc.tar.gz paichu.list test/
[[email protected] /home/nq]#tar tf etc.tar.gz
test/
test/test2
test/test.txt
test/test2.txt