Manage Archives With Atool - Atool Utility In Linux

Linux provides various tools for archiving and compressing files such as zip, bzip, gzip, tar, rar, etc. There are more tools that are not native to Linux, but provide good archiving and compressing abilities. With such a large number of tools at hand, sometimes it becomes difficult to remember all the commands. "Atool" allows you to manage these different file archives with a single command.

Atool.

Atool is a perl script that uses different tools or commands behind the scenes for different archive types. Atool comes with a number of commands like aunpack, apack, als, acat, adiff and arepack. These executables are just the symbolic links to atool command. Atool can handle various file archives like zip, compress(.z), jar, rar, 7z, bzip, gzip, rpm, deb, cpio, tar, tar.gz. tar.bz, tar.bz2, tar.7z and many more. It relies on the file extension for determining the archive type. If it is not possible to identify the archive with file extension, file command is used.

The commands available with atool are simple commands. Some examples of these commands are:

aunpack.

aunpack is used to extract an archive. It is similar to executing "atool -x" for extracting an archive.

$ aunpack file.tar.gz
file_feb
file_jan
file_mar
file.tar.gz: extracted to `file' (multiple files in root)

Using atool:

$ atool -x file.tar.gz
file_feb
file_jan
file_mar
file.tar.gz: extracted to `file' (multiple files in root)

acat.

The acat command or "atool -c" can be used to view a file from the archive.

$ acat file.tar.gz file_jan
file_jan
January

als.

To list contents of an archive, use als or "atool -l".

$ als file.tar.gz
-rw-r--r-- raghu/raghu 0 2012-08-20 12:29 file_mar
-rw-r--r-- raghu/raghu 9 2012-08-20 12:35 file_feb
-rw-r--r-- raghu/raghu 8 2012-08-20 12:36 file_jan

apack.

This command creates the archive. The same can be achieved through "atools -a".

$ apack dir1.tar.gz dir1/
dir1/
dir1/file1_2
dir1/file1_3
dir1/file1_1

$ file dir1.tar.gz
dir1.tar.gz: gzip compressed data, from Unix, last modified: Mon Aug 20 12:44:11 2012

The file command in above output shows that it is gzip compressed data. If you want to create the archive of some other type, just provide the corresponding extension.

arepack.

It repacks the archive into another format. In order to do this, it first extracts the archive into a temporary directory and then creates the new archive from this temporary directory. The original archive is not deleted.

$ arepack dir1.tar.gz dir1.7z
dir1/
dir1/file1_2
dir1/file1_3
dir1/file1_1

7-Zip 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30
p7zip Version 9.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)
Scanning

Creating archive ../dir1.7z

Everything is Ok
dir1.7z: saved 18 bytes

$ file dir1.7z
dir1.7z: 7-zip archive data, version 0.3

adiff.

adiff command shows the difference between two archives like diff command. "atool -d" does the same.

$ adiff dir1.7z firstdir.7z

7-Zip 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30
p7zip Version 9.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)

Processing archive: dir1.7z

Extracting dir1/file1_1
Extracting dir1/file1_2
Extracting dir1/file1_3
Extracting dir1

Everything is Ok

Folders: 1
Files: 3
Size: 11
Compressed: 196

7-Zip 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30
p7zip Version 9.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)

Processing archive: firstdir.7z

Extracting dir1/file1_1
Extracting dir1/file1_2
Extracting dir1/file1_3
Extracting dir1

Everything is Ok

Folders: 1
Files: 3
Size: 0
Compressed: 144
diff -ru Unpack-0875/dir1/file1_1 Unpack-9252/dir1/file1_1
--- Unpack-0875/dir1/file1_1 2012-08-20 13:03:21.000000000 +0530
+++ Unpack-9252/dir1/file1_1 2012-08-20 12:42:11.000000000 +0530
@@ -1 +0,0 @@
-first file

The atool command has some more options except these commands. You can manually provide the file format with -f option.

You can also see that what commands are running in background when you use the atool command using -E or --explain option. For example,

$ als -E file.tar.gz
tar tvzf file.tar.gz
-rw-r--r-- raghu/raghu 0 2012-08-20 12:29 file_mar
-rw-r--r-- raghu/raghu 9 2012-08-20 12:35 file_feb
-rw-r--r-- raghu/raghu 8 2012-08-20 12:36 file_jan

$ acat -E file.tar.gz file_feb
tar xOvzf file.tar.gz file_feb
file_feb
february

The -S or --simulate option runs atool in simulation mode. This option just displays the commands that would run but no changes to the filesystem are made.

$ atool -x -S dir1.tar.gz
mkdir Unpack-1227
tar xvzf dir1.tar.gz -C Unpack-1227

$ adiff -S dir1.7z firstdir.7z
mkdir Unpack-6603
mkdir Unpack-6480
7z x -oUnpack-6603 dir1.7z
7z x -oUnpack-6480 firstdir.7z
diff -ru Unpack-6603 Unpack-6480
rm -r Unpack-6603
rm -r Unpack-6480

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

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

All comments are subject to moderation.