Is there any program to provide a consistent interface across multiple archive types?

At the moment, if I download a compressed file, it could be any of a .tar.gz archive, a tar.bz2 arhive, a .zip archive or a .gz archive. And each time I do so, I have to remember what the command line options for that program are.

Is there any CLI program where I can just go:

undocompression somefile.??

and let it figure out what format the archive is in? (overly long name used to avoid conflicting with any real program)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can use p7zip. It automatically identifies the archive type and decompress it.

p7zip is the command line version of
7-Zip for Unix/Linux, made by an
independent developer.

7z e <file_name>

Method 2

I found this little snippet a while ago and have been using it since. I just have it in my .bashrc file

extract () {
if [ -f $1 ] ; then
    case $1 in
        *.tar.bz2)  tar xjf $1      ;;
        *.tar.gz)   tar xzf $1      ;;
        *.bz2)      bunzip2 $1      ;;
        *.rar)      rar x $1        ;;
        *.gz)       gunzip $1       ;;
        *.tar)      tar xf $1       ;;
        *.tbz2)     tar xjf $1      ;;
        *.tgz)      tar xzf $1      ;;
        *.zip)      unzip $1        ;;
        *.Z)        uncompress $1   ;;
        *)          echo "'$1' cannot be extracted via extract()" ;;
    esac
else
    echo "'$1' is not a valid file"
fi
}

Method 3

In Debian/Ubuntu there is the unp package, which is a Perl script that acts as a frontend for many archiving utilities.

Method 4

From another question: atool, which also handles various archive types and is more powerful than unp because it also handles listing of contents, finding differences between archives etc.

Method 5

GNU tar (and star) has at least some compression auto-detection capabilities:

tar xf foo.tar.gz
tar xf foo.tar.bz

just work.

Method 6

I think ark the KDE archiving tool can be run without a GUI. From the ark manpage

ark --batch archive.tar.bz2

Will extract archive.tar.bz2 into the current directory without showing any GUI.

Arks support of various archive formats depends on which apps you have installed (e.g. for rar it depends on unrar ), but I don’t know of any formats it can’t handle.

Method 7

I’m surprised no one mentioned the dtrx tool that was suggested in this answer.

Seems to fit the request to a tee.

Method 8

The Unarchiver supports extraction of about 50 different formats with a consistent interface.

By default, a directory is created if there is more than one top-level file or folder.

View its man-page.

The command line version supports Linux and is available here.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x