5

I sometimes get confused by the varying command line options I need to run common Unix archiving and compression software (e.g. gzip, bzip2, zip, tar).

Is there a program out there that can just Do What I Mean for common cases? For example:

program --compress --gzip foobar
program --extract foobar.tar.bz2
program --extract foo.zip

3 Answers 3

1

atool is designed for this job. A copy of the man page is available here.

To compress files use

apack ARCHIVE FILE

and to decompress them use

aunpack ARCHIVE

(alternatively you can use atool -a and atool -x respectively).

It works with pretty much any archive format you can think of including gzip, bzip, lzip, 7z, rar, ar, deb, rpm, jar[1] and most combinations of tar and a compression method.

The advantage of this over 7zip is that 7zip removes executable permissions. So, for example, 7zip makes it much more difficult to install software from archived sources because you need to manually chmod +x the appropriate files before running any make or any install scripts.


[1] The online man page linked is for an older version that doesn't handle jar files.

8

As example 7z.

7z a -tgzip foobar.gz foobar
7z e foobar.gz

Where a - add files to archive, -t{Type} - Set type of archive (7z, zip, gzip, bzip2 or tar), e - extract files from archive. More information man 7z.

2
  • You shouldn't need the -t option most of the time -- 7-zip will guess archive type from common file extensions if possible.
    – afrazier
    Jun 22, 2011 at 23:01
  • There's a major problem with 7zip: it will remove file permissions even when extracting archives that should preserve this information! This greatly complicates the installation of software from archives. Use atool instead (see my answer below).
    – dshepherd
    Jan 23, 2015 at 10:20
1

tar, when configured correctly, can do this all (except the unzip maybe) easily.

tar --create --gzip --file out.tar.gz in in2 in3
# same thing
tar -czf out.tar.gz in in2 in3

tar --extract --file in.tar
tar -xf in.tar

This will work for gzipped and bzip2ed files as well. (Assuming you actually have such programs installed.)

Edit: Oh yeah, forgot about the unzip. That's not included in tar presumably because of patent reasons or such. Simply use the unzip application to extract those:

unzip in.zip

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