linux檔案打包與壓縮的方法是什麼
打包與壓縮
將檔案或資料夾合併成一個包,然後透過壓縮演算法進行資料壓縮,減小包的體積,方便網路傳輸。
windows: zip rar linux: zip tar gz bz2 tar.gz tar.bz2 压缩算法: gzip bzip2
zip
是一個Windows和Linux中常用打包壓縮工具,支援的壓縮演算法是zip。
zip工具需要安装 yum install zip
zip壓縮一個檔案
# 格式 zip [参数] 压缩包名称 文件路径 [root@abc ~]# zip 123.zip 123.log adding: 123.log (deflated 87%) [root@abc ~]# ls -l
zip壓縮資料夾
# 需要一个-r参数去递归压缩文件夹下的所有内容 [root@abc ~]# zip -r dir.zip dir/ adding: dir/ (stored 0%) adding: dir/one/ (stored 0%) adding: dir/123.log (deflated 87%)
zip的靜默輸出
# -q:参数就是不输出任何打包信息 [root@abc opt]# zip -r -q etc.zip /etc/ [root@abc opt]# ls -l
zip解壓縮指令(unzip)
# 格式 unzip [参数] 压缩包路径 # unzip解压命令只能解压由zip打包的压缩文件 [root@abc ~]# unzip dir.zip Archive: dir.zip inflating: dir/123.log [root@abc ~]# # 其他压缩包由unzip解压时随即报错。 [root@abc opt]# unzip nginx-.tar.gz Archive: nginx-.tar.gz End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of nginx-.tar.gz or nginx-.tar.gz.zip, and cannot find nginx-.tar.gz.ZIP, period. # 查看压缩包中压缩那些内容,不解压? # 只查看压缩包内容不解压需要使用 -l 参数 [root@abc opt]# unzip -l dir.zip Archive: dir.zip Length Date Time Name --------- ---------- ----- ---- 0 03-11-2021 12:04 dir/ --------- ------- 0 1 file # 解压到指定目录(-d) [root@abc ~]# unzip -d /root/ etc.zip [root@abc opt]# cd /root/ [root@abc ~]# ls ] anaconda-ks.cfg dir.zip index.html test.pdf.gz xxxeth0xxx 系统优化.md 123.log demo.txt etc nginx-0.1.22.tar.gz test.txt 上传与下载.md 123.zip dir eth0xxx test xxxeth0 文件管理_(高级).pdf # 静默输出(-q) [root@abc ~]# rm -rf etc [root@abc ~]# unzip -q -d /root/ /opt/etc.zip [root@abc ~]# ls -l
tar
tar壓縮支援多種壓縮演算法
tar.gz gzip (用的最多)
tar.bz2 bzip2
gzip
透過gzip壓縮演算法,將檔案壓縮一定體積,有利於傳輸, 不支援打包
[root@abc ~]# ls -l total 4828 -rw-r--r-- 1 root root 244977 Mar 10 12:12 index.html [root@abc ~]# gzip index.html [root@abc ~]# ls -l
gzip壓縮一個目錄
[root@abc etc]# gzip -r /etc [root@abc etc]# ls
gzip解壓縮(-d)
[root@abc ~]# ls -l -rw-r--r-- 1 0 0 22652 Mar 10 12:12 index.html.gz [root@abc ~]# gzip -d index.html.gz [root@abc ~]# ls -l
bzip2
使用bzip2 壓縮演算法來壓縮一定體積的檔案。
[root@abc ~]# ls -l total 4828 -rw-r--r-- 1 root root 646165 Mar 9 10:31 123.log [root@abc ~]# bzip2 123.log [root@abc ~]# ls -l total 4240 -rw-r--r-- 1 root root 0 Mar 10 12:04 ]
bzip2解壓縮(-d)
bzip2解壓縮是針對於bzip2壓縮的壓縮套件來進行解壓縮。
[root@abc ~]# ls -l total 4240 -rw-r--r-- 1 root root 42210 Mar 9 10:31 123.log.bz2 [root@abc ~]# bzip2 -d 123.log.bz2 [root@abc ~]# ls -l
tar
tar其實是個打包工具,不具備壓縮功能,但可以使用參數呼叫壓縮工具來進行解壓縮。
tar参数 -c : 创建压缩 -f ; 指定压缩包名称 -z : 使用gzip压缩工具进行压缩 -j : 使用bzip2压缩工具进行压缩 -J : 使用xz压缩工具进行压缩 -t : 显示压缩包内容,不解压 -v : 显示压缩过程 -P : 允许使用绝对路径进行压缩 -x : 解压 -C : 指定解压路径 -h : 打包软连接 --exclude : 排除某些文件 --exclude-from :
參數
-c : 建立壓縮套件
-f : 指定壓縮套件名稱
[root@abc ~]# tar -c -f test.tar 123.log [root@abc ~]# ls -l
-z : 指定使用gzip壓縮工具進行壓縮
[root@abc ~]# tar -c -z -f test-one.tar 123.log [root@abc ~]# ls -l total 5084 -rw-r--r-- 1 root root 85279 Mar 11 15:56 test-one.tar # 注:使用-z参数,不会自动添加.gz后缀 [root@abc ~]# tar -c -z -f anaconda.tar.gz anaconda-ks.cfg [root@abc ~]# ls -l
- ##-j : 指定使用bzip2壓縮工具進行壓縮
[root@abc ~]# tar -c -j -f 123-bask-one.tar 123.log [root@abc ~]# ls -l
- -J : 指定使用xz壓縮工具進行壓縮
[root@abc test-tar]# tar -c -J -f etc.tar.xz /etc/ [root@abc ~]# ls -l
- -t : 查看壓縮套件內容
[root@abc ~]# tar -t -f 123-bak.tar.bz2 123.log [root@abc ~]#
- #-v :顯示壓縮套件壓縮過程
[root@abc ~]# tar -x -v -f etc.tar -C /opt/
- -P : 允許使用絕對路徑進行打包
[root@abc ~]# tar -c -P -f 123-three.tar /etc/passwd [root@abc ~]# tar -c -f 123-three.tar /etc/passwd tar: Removing leading `/' from member names [root@abc ~]#
- -x : 解壓縮##
# tar解压是按照原来的路径进行解压 [root@abc test]# tar -x -f etc.tar # tar会自动识别压缩功能
登入後複製
- -C :指定解壓縮路徑
-
[root@abc ~]# tar -x -f etc.tar -C /opt/ tar: Removing leading `/' from member names [root@abc ~]# cd /opt/ [root@abc opt]# ls abc23 dir dir.zip etc nginx-0.1.22.tar.gz nginx-.tar.gz xxx [root@abc opt]#
登入後複製
- –exclude : 排除某些檔案
-
[root@abc test-tar]# tar -c -f abc.tar ./* --exclude=abc7 --exclude=abc5 --exclude=abc1 [root@abc test-tar]# tar -t -f abc.tar ./abc2 ./abc3 ./abc4 ./abc6 ./abc8 ./abc9 [root@abc test-tar]#
登入後複製
- –exclude-from : 根據某個檔案清單排除多個檔案
-
#
[root@abc test-tar]# cat list.txt abc995 abc996 abc997 abc998 abc999 [root@abc test-tar]# tar -c -f abc.tar ./* --exclude-from=list.txt
登入後複製
- -h : 打包軟體連線
-
[root@abc test-tar]# tar -c -h -f bin-h.tar /bin
登入後複製
以上是linux檔案打包與壓縮的方法是什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

VS Code 系統要求:操作系統:Windows 10 及以上、macOS 10.12 及以上、Linux 發行版處理器:最低 1.6 GHz,推薦 2.0 GHz 及以上內存:最低 512 MB,推薦 4 GB 及以上存儲空間:最低 250 MB,推薦 1 GB 及以上其他要求:穩定網絡連接,Xorg/Wayland(Linux)

Linux系統的五個基本組件是:1.內核,2.系統庫,3.系統實用程序,4.圖形用戶界面,5.應用程序。內核管理硬件資源,系統庫提供預編譯函數,系統實用程序用於系統管理,GUI提供可視化交互,應用程序利用這些組件實現功能。

雖然 Notepad 無法直接運行 Java 代碼,但可以通過借助其他工具實現:使用命令行編譯器 (javac) 編譯代碼,生成字節碼文件 (filename.class)。使用 Java 解釋器 (java) 解釋字節碼,執行代碼並輸出結果。

VS Code擴展安裝失敗的原因可能包括:網絡不穩定、權限不足、系統兼容性問題、VS Code版本過舊、殺毒軟件或防火牆干擾。通過檢查網絡連接、權限、日誌文件、更新VS Code、禁用安全軟件以及重啟VS Code或計算機,可以逐步排查和解決問題。

要查看 Git 倉庫地址,請執行以下步驟:1. 打開命令行並導航到倉庫目錄;2. 運行 "git remote -v" 命令;3. 查看輸出中的倉庫名稱及其相應的地址。

VS Code 可以在 Mac 上使用。它具有強大的擴展功能、Git 集成、終端和調試器,同時還提供了豐富的設置選項。但是,對於特別大型項目或專業性較強的開發,VS Code 可能會有性能或功能限制。

在 Visual Studio Code(VSCode)中編寫代碼簡單易行,只需安裝 VSCode、創建項目、選擇語言、創建文件、編寫代碼、保存並運行即可。 VSCode 的優點包括跨平台、免費開源、強大功能、擴展豐富,以及輕量快速。

vscode 內置終端是一個開發工具,允許在編輯器內運行命令和腳本,以簡化開發流程。如何使用 vscode 終端:通過快捷鍵 (Ctrl/Cmd ) 打開終端。輸入命令或運行腳本。使用熱鍵 (如 Ctrl L 清除終端)。更改工作目錄 (如 cd 命令)。高級功能包括調試模式、代碼片段自動補全和交互式命令歷史。
