Unarc - unpack archives into their own directory


Sometimes when you unpack a .tar.gz file, it spills files all over your current directory, so you have to make a new directory to unpack in if you want to avoid a mess. But other .tar.gz files have their own top-level directory, so unpacking in a new directory is not necessary and creates a different kind of mess.

The answer is unarc, which unpacks an archive and creates a top-level directory if it's needed. Unarc works with lots of archives, not just tarballs - .tar.bz2, .zip and even .rpm are supported. It's a simple and tidy way to unpack most archives.

There is a companion program arcdir which provides a uniform way to archive directories into tarfiles, zipfiles and so on. It should be easy to add support for new filetypes and archivers.


unarc filename(s)
Unpack the archives specified, each into its own directory. The archiver to use is chosen based on the filename.

arcdir directory(s)
Archive each directory individually, using the default archive type tar.bz2. Each directory will be archived into dirname.tar.bz2.

arcdir -t type directory(s)
where type is one of zip, tar.gz, etc.
Archive directories into a type of archive you choose. For example, arcdir -t zip foo will archive foo/ into foo.zip.


The latest version is 0.2.8. This fixes a possible infinite loop when unpacking on some systems.


Copy unarc and arcdir to somewhere in your PATH. They use the library archive_types.pl, which you need to copy to your Perl library directory. To find out where Perl looks for libraries, try this:

perl -e 'print "$_\n" foreach @INC'
and copy archive_types.pl to one of the directories listed, /usr/lib/perl5/site_perl/5.x/ would be a good choice. Alternatively, create your own directory for Perl libraries and add it to PERL5LIB. (I'm still looking for a better way to do this, or at least a better way to explain it.)

To unpack some of the more esoteric archive types you will need to first install the program pip which works around the fact that some programs (like unzip) cannot read their input from stdin.

There is a test suite included. Try this (with archive_types.pl in the current directory):
perl archive_types.pl --test-archivers | grep -E 'ok|fail|skip'
and check that nothing fails. You may get complaints from cpio about 'truncating inode number', they can be safely ignored.

The list of archivers supported (and these instructions) assume that you have the GNU utilities on your system, rather than the plain old Unix or BSD versions. However it shouldn't be too difficult to change things to support non-GNU archivers.

Adding your own archivers

Take a look at archive_types.pl. You will need three commands:

The set of commands for 'tar' is a good example, some of the others go through horrible contortions.


All the files are in the public domain. This means there are no copyright restrictions, you may do what you wish with them. Of course, giving credit would be appreciated (but not required).

They are offered as-is with no warranty whatsoever.


When unpacking zipfiles created by tools such as pkzip on MS-DOS, uppercase filenames are converted to lowercase. But when listing the contents of such archives, they aren't. This is because zipinfo doesn't support the -L option.


Please contact me, Ed Avis <ed@membled.com> with any suggestions, bug reports or if you would like me to add a new archive type.

These programs have a web page at http://membled.com/work/apps/unarc/.

Stop software patents in the EU