unp: single command to extract archives

We explored patool in one of our earlier articles. unp (abbreviation of unpack) is a similar utility which detects the compression type of a file and extracts it. Though it is less powerful than patool by flexibility, it compensates through ease of use, supports commonly used formats and does what it claims. unp is written in python.

unp doesn’t depend on file extension and can detect the type of archive from its magic number. Currently supported compression formats are:

  • 7zip Archives (*.7z)
  • AR Archives (*.a)
  • Apple Disk Image (*.dmg; *.sparseimage) [OS X only]
  • Bz2 Compressed Files (*.bz2)
  • Bz2 Compressed Tarballs (*.tar.bz2)
  • Gzip Compressed Files (*.gz)
  • Gzip Compressed Tarballs (*.tar.gz; *.tgz)
  • Uncompressed Tarballs (*.tar)
  • WinRAR Archives (*.rar)
  • Windows Cabinet Archive (*.cab)
  • XZ Compressed Files (*.xz)
  • XZ Compressed Tarballs (*.tar.xz)
  • Zip Archives (*.zip; *.egg; *.whl; *.jar)


To install unp on Ubuntu:

$ sudo apt-get install unp


unp is very simple to use. It takes as many archives you want as arguments and extracts them to the current directory preserving the directory structure:

$ unp ~/Downloads/archive1.zip ~/archive2.rar

On GitHub: unp

Bash script

While unp doesn’t depend on file extension, you can use a simple bash script to extract files based on extension. Thanks to a Reddit user for suggesting the following:

function extract()
if [ -f $1 ] ; then
     case $1 in
            tar xvf $1     
            bunzip2 $1      
            unrar x $1      
            gunzip $1       
            unzip $1        
            uncompress $1   
            7z x $1         
            echo "'$1' cannot be extracted via extract" 
    echo "I do not understand the extension for '$1' yet!"

Similar software

  1. dtrx
  2. atool
  3. unar (lot of dependencies, including GNUstep)

Leave a Reply

Your email address will not be published. Required fields are marked *