后缀 | 工具 | 压缩 | 解压 |
---|---|---|---|
.tar | tar | tar cvf FileName.tar DirName | tar xvf FileName.tar |
.gz | gzip | gzip FileName | gzip -d FileName.gz |
.bz2 | bzip2 | bzip2 -z FileName | bzip2 -d FileName.bz2 |
.Z | compress | compress FileName | compress -d FileName.Z |
.xz | xz | xz -z FileName | xz -d FileName.xz |
.zip | (un)zip | zip FileName.zip DirName | unzip FileName.zip |
.rar | rar | rar a FileName.rar DirName | rar x FileName.rar |
.lha | lha | lha -a FileName.lha FileName | lha -e FileName.lha |
.tar.gz | tar+ | tar zcvf FileName.tar.gz DirName | tar zxvf FileName.tar.gz |
.tgz | tar+ | tar zcvf FileName.tar.gz DirName | tar zxvf FileName.tar.gz |
.tar.bz2 | tar+ | tar jcvf FileName.tar.bz2 DirName | tar jxvf FileName.tar.bz2 |
.tar.Z | tar+ | tar Zcvf FileName.tar.Z DirName | tar Zxvf FileName.tar.Z |
.tar.xz | tar+ | tar Jcvf FileName.tar.xz DirName | tar Jxvf FileName.tar.xz |
Linux 的解压命令太繁琐了,即便是运维老司机也会感到头痛,这里我分享一个 Shell 脚本,可以一键解压以下格式的文件:
.zip, .rar, .bz2, .gz, .tar, .tbz2, .tgz, .Z, .7z, .xz, .exe, .tar.bz2, .tar.gz, .tar.xz, .arj, .cab, .chm, .deb, .dmg, .iso, .lzh, .msi, .rpm, .udf, .wim, .xar .cpio, .cbr, .cbz, .cb7, .cbt, .cba
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr|*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id < ./"$n" ;;
*.cba|*.ace) unace x ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
IFS=$SAVEIFS
安装步骤:
- 编辑 .bashrc 文件:
vim ~/.bashrc
- 复制 Shell 代码到 .bashrc 文件
- 启动 bash shell:
source ~/.bashrc
解压测试:
- 下载 Python 源码包:
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
- 解压 tar.xz 文件:
extract Python-3.7.0.tar.xz