Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)

share|improve this question
    
I couldn't find or create any tags such as archive, compression etc. Could someone else add the correct one? –  Macha Aug 28 '10 at 15:43
    
@Tshepang: Fixed. –  Macha Nov 29 '10 at 12:45
add comment

6 Answers

up vote 7 down vote accepted

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>

share|improve this answer
add comment

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
}
share|improve this answer
    
This is more effective than the accepted answer, since 7z e foo.tar.gz just leaves you with a foo.tar file. –  Wilfred Hughes May 17 at 20:44
add comment

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

share|improve this answer
add comment

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

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

just work.

share|improve this answer
    
It does depend on the version of tar which formats it can autodetect but other than that it works well... IIRC star is actually a more standardized way, where GNU's tar is a non standard extension. –  xenoterracide Aug 28 '10 at 17:05
    
Latest version of GNU tar can uncompress all compressed archives, which are created with any of the compression filter switches (z, j, J, --lzma), it will detect compression automatically. –  polemon Nov 29 '10 at 15:58
    
@xenoterracide: Well, the author of star has criticized GNU tar a lot in his usual style - these writings could be biased (ignoring bad points about star and good points about GNU tar), contain probably some FUD and are probably outdated. –  maxschlepzig Nov 29 '10 at 17:29
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.