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
解压。