I keep forgetting all the corresponding extract commands for every compression format.

So I was thinking about writing a script that merely maps file extensions to the appropriate extract command. But I guess something like this already exists, I just can't find it.

I would be happy with something like file-roller, but file-roller is a GUI tool.


A couple of suggestions:


unp (available from software-center) is a small perl module that will decompress a wide variety of archives into the current folder. Use unp -s for the archive formats it supports

By default, it decompresses archives into the current folder.


file-roller itself can be run from the command line. Use file-roller -h <archive name> to decompress the archive.


From here, to put in your .bashrc:

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()" ;;
      echo "'$1' is not a valid file"
  • Add an example of how to use it? – MiniGod Dec 9 '14 at 11:57
  • 4
    extract file.zip – frabjous Dec 16 '14 at 1:45

What hasn't yet been mentioned is the swiss-army-knife of command-line utilities: atool; it is available in the repositories: click atool Install atool or run sudo apt-get install atool.

atool is actually a script comprising various functions such as aunpack, apack, als, acat, adiff, and arepack. Probably the most common use of the program is to extract archives using the aunpack command. There are quite a few interesting and useful options, but the basic way to extract most archives is just to run, for example,

aunpack myarchive.tar

The support for tar, 7z, zip, jar, rar, ar, lha and many more archive formats and their variations are documented by entering man atool in the terminal or by viewing the Ubuntu manpage online.

So, the useful thing is that if you have a tar, zip and gz archive in the same folder, all you need to do to extract them all is to run

aunpack -e *

and all supported archives will be unpacked with their folder structure retained. If the name of the resulting folder already exists, it will not be overwritten, but will be given a unique name like unpack-5645.

Or if you want to choose just one type of archive and unpack them all, instead use

aunpack -e *.zip

If you need files unpacked directly in a particular directory, with only the sub folder directory structure being retained (if it exits), enter, for example,

aunpack -e Scripts11.zip -X /home/mike/Videos

If a file with the same name already exists, you will be prompted for an action either to rename or overwrite unless you have specified the force option (-f) in the command.

As the manpage notes, aunpack first extracts

files to a unique (temporary) directory, and then mov[es] its contents back if possible. This also prevents local files from being overwritten by mistake.

With the other tools, other actions are possible, as mentioned by the man page:

  • apack creates archives from the files or folder specifies or stdin
  • als lists files within the specifies archive
  • acat enables one to extract archive files to stdout
  • adiff enables you to compare the two archives specified
  • arepack makes it possible to convert one archive format to another by placing the contents of the original archive in a temporary folder and then repacking the new one.

There are many more useful options for all of the utilities, but probably the one used the most will be aunpack, as that makes it so easy to extract multiple, different archives. It is great to be able to just issue one command and be able to extract multiple different archive formats without having to use the various commands for tar, zip, etc.

For a very recent article describing how to integrate the atool functions into the custom actions of your filemanager, such as Thunar, see this online magazine.


There is a tool called dtrx -- do the right extraction.

Install it from the Ubuntu repositories and run dtrx somefile.someext. The tool will interactively query the user about nested archives (zip of zip files).

dtrx is a sophisticated version of frabjous's extract.


What kind of formats do you need to deal with? One way is to write a shell script, which checks the extensions of its argument. Or, if all you deal with is variations on .tar.*, simply doing tar -xf will deal with most of those automatcially. (I therefore only remember that and unzip which suffice for everything I usually come across.)

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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