Decompress many: Difference between revisions

From SlackWiki
Jump to navigation Jump to search
(Created page with "Category:Tips <pre> #Bash function to decompress (unarchive) may formats. function unarc() { if [ -f $1 ]; then case $1 in *.tar.*) tar xvf $1;; *.bz2) b...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Tips]]
[[Category:Tips]]
<pre>
<pre>
#Bash function to decompress (unarchive) may formats.
# bash function: decompress an archive file of any of many formats
# Decompress archive file.
function unarc()
function unarc()
{
{
Line 24: Line 25:
       *.Z) uncompress $1;;
       *.Z) uncompress $1;;
       *.zip) unzip $1;;
       *.zip) unzip $1;;
       *) echo '"$1" cannot be extracted.';;
       *) echo '"$1" extraction error.';;
     esac
     esac
   else echo '"1" cannot be extracted.';
   else echo '"1" nonexistent?';
   fi
   fi
}
}
</pre>
</pre>

Latest revision as of 11:31, 28 August 2022

# bash function: decompress an archive file of any of many formats
# Decompress archive file.
function unarc()
{
  if [ -f $1 ]; then
    case $1 in
      *.tar.*) tar xvf $1;;
      *.bz2) bunzip2 $1;;
      *.gz) gunzip $1;;
      *.jar) jar xvf $1;;
      *.lha) lha e $1;;
      *.tar) tar xvf $1;;
      *.tar.bz2) tar xvf $1;;
      *.tar.gz) tar xvf $1;;
      *.tar.xz) tar xvf $1;;
      *.tar.Z) tar xvf $1;;
      *.rar) rar x $1;;
      *.7z) 7z x $1;;
      *.tbz2) tar xvf $1;;
      *.tgz) tar xvf $1;;
      *.txz) tar xvf $1;;
      *.xz) unxz $1;;
      *.Z) uncompress $1;;
      *.zip) unzip $1;;
      *) echo '"$1" extraction error.';;
    esac
  else echo '"1" nonexistent?';
  fi
}