Debian系統壓縮文件的常用方法
tar是Debian下功能強大的打包工具,可與gzip、bzip2等壓縮工具結合使用,生成.tar.gz
(gzip壓縮,速度快)、.tar.bz2
(bzip2壓縮,壓縮比高)等格式。
tar -czvf archive.tar.gz /path/to/directory_or_file
參數說明:-c
(創建歸檔)、-z
(gzip壓縮)、-v
(顯示詳細過程)、-f
(指定歸檔文件名)。tar -cjvf archive.tar.bz2 /path/to/directory_or_file
參數說明:-j
(bzip2壓縮),壓縮比高于gzip但速度較慢。tar -xzvf archive.tar.gz # 解壓.tar.gz
tar -xjvf archive.tar.bz2 # 解壓.tar.bz2
.gz
格式(原始文件會被刪除)。gzip /path/to/file # 壓縮
gunzip /path/to/file.gz # 解壓
.bz2
格式(原始文件會被刪除)。bzip2 /path/to/file # 壓縮
bunzip2 /path/to/file.bz2 # 解壓
zip格式廣泛兼容Windows系統,適合需要跨平臺分享的場景。
zip -r archive.zip /path/to/directory_or_file
參數說明:-r
(遞歸壓縮目錄及子內容)。unzip archive.zip # 解壓到當前目錄
unzip archive.zip -d /path/to/destination # 解壓到指定目錄
若偏好可視化操作,Debian預裝的Archive Manager(歸檔管理器)支持多種格式:
sudo
提權)。screen
或tmux
保持會話,避免因終端斷開導致中斷。p7zip-full
包(sudo apt install p7zip-full
),使用7z a archive.7z file_or_directory
壓縮,7z x archive.7z
解壓。