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)
Installation
To install unp on Ubuntu:
$ sudo apt-get install unp
Usage
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|*.tar.xz|*.tar.bz2|*.tar.gz|*.txz|*.tbz2|*.tgz) tar xvf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted via extract" ;; esac else echo "I do not understand the extension for '$1' yet!" fi }
Similar software