Commandline program to extract archives with automatic subdirectry detection

Posted by ?????? on Super User See other posts from Super User or by ??????
Published on 2012-12-09T04:44:05Z Indexed on 2012/12/09 5:07 UTC
Read the original article Hit count: 557

Filed under:
|
|
|

The title already says it.
What I'm looking for is essentially the pure commandline counterpart to ark -ba <path> (on KDE), or file-roller -h <path> (on GNOME/Unity).

Unfortunately, both ark and file-roller require X to be running. I'm aware that it is relatively simple to write a tool that detects archives based on their file extension, and then runs the appropiate program:

#!/bin/bash
if [[ -f "$1" ]] ; then
    case $1 in
        *.tar.bz2) tar xjvf $1 ;;
        *.tar.gz) tar xzvf $1 ;;
        *.bz2) bunzip2 $1 ;;
        *.rar) rar x $1 ;;
        *.gz) gunzip $1 ;;
        *.tar) tar xf $1 ;;
        *.tbz2) tar xjvf $1 ;;
        *.tgz) tar xzvf $1 ;;
        *.zip) unzip $1 ;;
        *.Z) uncompress $1 ;;
        *.7z) 7z x $1 ;;
        *) echo "'$1' cannot be extracted with this utility" ;;
    esac
else
    echo "path '$1' does not exist or is not a file"
fi

However, that doesn't take care of subdirectory detection (and in fact, many extraction programs do not even supply such an option).
So might there be a program that does exactly that?


I wasn't sure whether or not to ask on askubuntu.com, because this question isn't really about Ubuntu, but rather about any Linux operating system. My apologies if this question does not fit in here.

© Super User or respective owner

Related posts about linux

Related posts about command-line