#!/usr/bin/env bash # # extract - Extract wide range of various archive types with native tools # # Copyright (C) 2021 Pekka Helenius # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ##################################### 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]" return 1 else for n in $@ do if [ -f "$n" ] ; then case "${n%,}" in *.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar) tar xvf "$n" ;; *.lzma) unlzma ./"$n" ;; *.bz2) bunzip2 ./"$n" ;; *.rar) unrar x -ad ./"$n" ;; *.gz) gunzip ./"$n" ;; *.zip) unzip ./"$n" ;; *.z) uncompress ./"$n" ;; *.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar) 7z x ./"$n" ;; *.xz) unxz ./"$n" ;; *.exe) cabextract ./"$n" ;; *) echo "extract: '$n' - unknown archive method" return 1 ;; esac else echo "'$n' - file does not exist" return 1 fi done fi