Linux 解压文件常用命令速查
说明与准备
常用格式与命令一览
| 格式 | 解压命令示例 | 备注 |
|---|---|---|
| .tar | tar -xvf file.tar |
仅归档,未压缩 |
| .tar.gz / .tgz | tar -xzvf file.tar.gz |
使用 gzip |
| .tar.bz2 / .tbz2 | tar -xjvf file.tar.bz2 |
使用 bzip2 |
| .tar.xz / .txz | tar -xJvf file.tar.xz |
使用 xz |
| .gz | gunzip file.gz |
解压为 file |
| .bz2 | bunzip2 file.bz2 |
解压为 file |
| .xz | xz -d file.xz |
解压为 file |
| .zip | unzip file.zip |
跨平台常用 |
| .rar | unrar x file.rar |
需安装 unrar |
| .7z | 7z x file.7z |
需安装 p7zip |
指定解压目录与查看内容
tar -xzvf file.tar.gz -C /path/to/destunzip file.zip -d /path/to/desttar -tf file.tar.gzunzip -l file.zipunzip -o file.ziptar -xzvf file.tar.gz path/in/archive/file.txt安装缺失的解压工具
sudo apt-get updatesudo apt-get install unzip p7zip-full unrarsudo yum install unzip p7zip unrar实用示例与排错要点
tar -xzvf project.tar.gz -C ~/projects/for z in *.zip; do unzip "$z" -d "${z%.*}"; doneunrar x archive.rarls -l 确认压缩包路径与名称。unzip -O GBK 中文文件.zip