patool: extract archives with one tool

I remember a former colleague who would always confuse the switches for gzip and bzip2 to tar. That led to a lot of confusion among people when he sent packages to them. However, I do not blame him. Using compressed archive files on Linux needs you to remember a lot of switches. Though tar can detect the file format (gzip/bzip2) nowadays while extracting, how about a tool that could handle many more compression types?

Fortunately, such a tool exists! It’s patool, a utility written in Python. Think of it as your cmdline File Roller or XArchiver. It remembers all the switches and options so that you don’t have to. patool detects the file type using good old file command and then it calls the appropriate external program to operate on the file. While generating output archives it determines the file type from the extension provided in the cmdline for the output file. It supports the following compression formats:

7z (.7z), ACE (.ace), ADF (.adf), ALZIP (.alz), APE (.ape), AR (.a), ARC (.arc), ARJ (.arj), BZIP2 (.bz2), CAB (.cab), COMPRESS (.Z), CPIO (.cpio), DEB (.deb), DMS (.dms), FLAC (.flac), GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), SHN (.shn), TAR (.tar), XZ (.xz), ZIP (.zip, .jar) and ZOO (.zoo)

Let’s explore this powerful tool.

  • Install patool on Ubuntu
    $ sudo apt-get install patool
  • List the file types supported on your system
    $ patool formats
  • List the files in an archive
    $ patool list archive
  • Extract archives to a specific directory (default is working directory)
    $ patool extract archive1 archive2 --outdir path_to_target_dir
  • Create an archive
    $ patool archive file dir ...
  • Test the integrity of an archive
    $ patool test archive
  • Search archive contents for a pattern using grep -r
    $ patool search pattern archive
  • Show the difference between two archives using diff -urN
    $ patool diff archive1 archive2
  • Repack to a new format
    $ patool repack archive archive_new
  • Show more information
    $ patool --verbose ...

To make things even simpler you can always add aliases to your .bashrc. For example,

alias pe='patool extract'

Webpage: patool

2 thoughts on “patool: extract archives with one tool”

Leave a Reply

Your email address will not be published. Required fields are marked *