后缀
工具
压缩
解压
.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 ."
echo " extract [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: &#39;$n&#39; - unknown archive method"
return 1
;;
esac
else
echo "&#39;$n&#39; - file does not exist"
return 1
fi
done
fi
}
IFS&#61;$SAVEIFS
安装步骤&#xff1a;
编辑 .bashrc 文件&#xff1a;vim ~/.bashrc
复制 Shell 代码到 .bashrc 文件
启动 bash shell&#xff1a;source ~/.bashrc
解压测试&#xff1a;
下载 Python 源码包&#xff1a;wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
解压 tar.xz 文件&#xff1a;extract Python-3.7.0.tar.xz