26

With an increasing number of archive/compression file formats, is there a single free/open-source command line tool to rule them all? Perhaps something with a consistent / unified set of flags? (note my friendly implicit reference to tar)

I once run into a set of aliases meant to largely simplify the task of compressing/de-compressing files with bindings to tar and other utils, but I can't find this anymore.

Update: How can I configure something like atool to not use unzip to extract zip files (which apparently can't handle files larger than 4GB) and to use gunzip instead?

$ aunpack large_file.zip
error:  Zip file too big (greater than 4294959102 bytes)
Archive:  large_file.zip
warning [large_file.zip]:  1491344848 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [large_file.zip]:  start of central directory not found;
  zipfile corrupt.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)
aunpack: unzip ...: non-zero return-code
5

4 Answers 4

27

I use atool. It does the job. It works with many, though not all formats:

tar, gzip, bzip2, bzip, lzip, lzop, lzma, zip, rar, lha, arj, arc, p7zip etc.

These compression tools are still needed, though as atool is simply a front end for them.

I particularly like the als command it provides which lists the contents of any supported archive format.

The main atool command uses its own flags for extracting archives (passing the appropriate flags to the specific underlying extraction tools).

Oh, and it's in some distributions' repositories (Fedora in my case, though as I recall, back when I used Ubuntu it wasn't in their repos then. and I installed from a tarball.).

Update on Repositories: atool is in the following distributions' repositories (current releases checked only):

  • Fedora
  • Debian (thanks @terdon, and, presumably, it's derivatives like Ubuntu)
  • Ubuntu (q.e.d., and, presumably, derivatives like Mint)
  • Open Suse
  • CentOS (and, presumably, RHEL)
  • Arch Linux

I'm sure there are others... plausibly, most modern distributions.

Answer for Updated Question "How can I configure something like atool to not use unzip to extract zip files ... and to use gunzip instead":

Edit the atool config file ~/.atoolrc and add the line:

path_unzip /usr/bin/gunzip

with the correct path to your gunzip program.

See the man page for the complete list of possible variables you can put in this config file, of which there are a lot. If the command line options necessary for gunzip are different than unzip, you may have to modify the atool source (perl) itself.

3
  • Thanks. This looks great. Do you know if, aside from being able to download the tarball, there is a (git/bzr) repository for it, or perhaps for a fork of it? Apr 22, 2013 at 22:59
  • There doesn't appear to be a git repo for it. There is a, shudder, cvs repo: savannah.nongnu.org/cvs/?group=atool . However, the source is in the tarball and the tool is written in perl, so easily modifiable by you or anyone who feels the urge.
    – SuperMagic
    Apr 22, 2013 at 23:40
  • 1
    @user815423426 it is also in the Debian repos.
    – terdon
    Apr 23, 2013 at 0:47
11

Here's a little shell function that takes care of several archive types.

extract () {
    if [ ! -f "$1" ] ; then
        echo "'$1' does not exist."
        return 1
    fi

    case "$1" in
        *.tar.bz2)   tar xvjf "$1"   ;;
        *.tar.xz)    tar xvJf "$1"   ;;
        *.tar.gz)    tar xvzf "$1"   ;;
        *.bz2)       bunzip2 "$1"    ;;
        *.rar)       rar x "$1"      ;;
        *.gz)        gunzip "$1"     ;;
        *.tar)       tar xvf "$1"    ;;
        *.tbz2)      tar xvjf "$1"   ;;
        *.tgz)       tar xvzf "$1"   ;;
        *.zip)       unzip "$1"      ;;
        *.Z)         uncompress "$1" ;;
        *.xz)        xz -d "$1"      ;;
        *.7z)        7z x "$1"       ;;
        *.a)         ar x "$1"       ;;
        *)           echo "Unable to extract '$1'." ;;
    esac
}

I found the original version of this function somewhere online and modified it a bit to extract ar archives and xz compressed tar archives.

3
  • This looks great. Is this for bash? Apr 22, 2013 at 21:14
  • I've only tested this with bash and zsh, but it should work with sh as well.
    – user26112
    Apr 22, 2013 at 21:15
  • This is exceptionally aesthetically pleasing for a shell function. One caveat would be that you'd want to make sure you've got all the relevant binaries installed, or remove lines for those you don't have installed.
    – bgvaughan
    Apr 26, 2013 at 17:19
3

The AVFS filesystem presents a view of the filesystem where every archive file (e.g. /path/to/foo.zip) is accessible as a directory (~/.avfs/path/to/foo/zip# for this example). AVFS provides read-only access to most common archive file formats.

mountavfs
cp -Rp ~/.avfs$PWD/large_file.zip\# extraction_directory

Avfs uses external helpers which can be easily configured by editing files in /usr (unfortunately there's no way as of avfs 1.0 to use files in /usr/local or in your home directory, you need to edit files in /usr or recompile). /usr/share/avfs/extfs/ext-uzip is the script to deal with .zip files, change it if you don't want to use /usr/bin/unzip. You may be able to get away with using 7z instead: try editing /usr/share/avfs/extfs/extfs.ini and change the line ext-uzip to u7z .zip.

1

libarchive is a Multi-format archive and compression library that supports many archive and compression formats.

bsdtar and bsdcpio are command-line interfaces to that with a tar-like a cpio-like API respectively.

So it you're already familiar with either of those utilities, that's one command-line interface less to learn.

To unpack your .iso, .zip, .cab, .7z, .tar.gz.xz.bz2... file, it's just:

bsdtar xf file.<ext>

Like you would do tar xf file.tar with a traditional tar command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .