Home > System Tutorial > LINUX > Linux command line universal decompression command

Linux command line universal decompression command

WBOY
Release: 2024-02-05 12:54:23
forward
1050 people have browsed it

这次我将和大家分享一个非常实用的万能解压命令。

在Linux系统下,有多种压缩包格式可供选择,而在命令行下解压不同格式的压缩包时,需要使用不同的命令和参数。对于我们来说,记住这么多命令是相当困难的。

不过,我们可以编写一个万能的解压命令,以替代这些繁琐的解压命令,这样我们只需要记住一条命令即可。

以下是具体的步骤分享:

1、在用户目录创建一个.autoex.sh脚本

Linux command line universal decompression command

脚本的内容如:

#copy from https://ynome.wordpress.com/2013/04/14/linux-%E9%80%9A%E7%94%A8%E8%A7%A3%E5%8E%8B/

ex () {
        if [[ -z “$1” ]] ; then
               print -P “usage: \e[1;36mex\e[1;0m ”
               print -P ”       Extract the file specified based on the extension”
        elif [[ -f $1 ]] ; then
           case $1 in
             *.tar)       tar xvf  $1    ;;
             *.tbz2)      tar xvf  $1    ;;
             *.tgz)       tar xvf  $1    ;;
             *.tar.bz2)   tar xvf  $1    ;;
             *.tar.gz)    tar xvf  $1    ;;
             *.tar.xz)    tar xvf  $1    ;;
             *.tar.Z)     tar xvf  $1    ;;
             *.bz2)       bunzip2v $1    ;;
             *.rar)       rar x $1       ;;
             *.gz)        gunzip $1      ;;
             *.zip)       unzip $1       ;;
             *.Z)         uncompress $1  ;;
             *.xz)        xz -d $1       ;;
             *.lzo)       lzo -dv $1     ;;
             *.7z)        7z x $1        ;;
             *)           echo "'$1' cannot be extracted via extract()" ;;
           esac
       else
         echo “‘$1’ is not a valid file”
       fi
    }


             # *.tar)       tar xvf  $1     ;;
             # *.tbz2)      tar xvjf $1    ;;
             # *.tgz)       tar xvzf $1    ;;
             # *.tar.bz2)   tar xjvf $1    ;;
             # *.tar.gz)    tar xvzf $1    ;;
             # *.tar.xz)    tar Jxf  $1    ;;
             # *.tar.Z)     tar xvZf $1    ;;
Copy after login

脚本来源:https://github.com/zqb-all/git-dot-files/blob/master/.autoex.sh

2、修改.bashrc文件

Linux command line universal decompression command

增加如下内容:

if [ -f ~/.autoex.sh ]; then
     . ~/.autoex.sh
fi
Copy after login
Linux command line universal decompression command

修改完成之后,执行如下命令使之生效:

source ~/.bashrc
Copy after login

3、解压测试

解压命令为:

ex file
Copy after login

(1)解压.zip后缀压缩文件

Linux command line universal decompression command

(2)解压.tar.xz后缀压缩文件

Linux command line universal decompression command

(3)解压.7z后缀压缩文件

Linux command line universal decompression command

因为这个命令能满足大多数常见情况解压的使用所以我们称之为万能命令,但是并未可以满足所有情况,我们可以根据实际使用情况修改完善.autoex.sh来完善这个万能解压命令ex。

The above is the detailed content of Linux command line universal decompression command. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template