Linux compression command and decompression script

suffix tool compress decompression
.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 DirName unzip
.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

The decompression command of Linux is too cumbersome, even the old driver of operation and maintenance will feel headache. Here I share a shell script, which can decompress the following files with one click:

.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

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]"
    for n in "[email protected]"
      if [ -f "$n" ] ; then
          case "${n%,}" in
                         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 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
          echo "'$n' - file does not exist"
          return 1


Installation steps:

  1. Edit the. Bashrc file:vim ~/.bashrc
  2. Copy the shell code to the. Bashrc file
  3. Start bash shell:source ~/.bashrc

Decompression test:

  1. Download Python source code package:wget
  2. Decompression tar.xz File:extract Python-3.7.0.tar.xz