Q:

What is the difference in various commands for compressing files in linux?

What are the commands for compressing files in linux and what are the difference between them? (for example: tar, gzip, rar).
I'm working on Linux Mint 11 and doing a script for compressing files. I need:

1. support for password encryption (and decryption)
2. support for division of file
3. support for level of compression

Which type of compressing can I use in Linux Mint 11 (14 eventually) and is the best for me?

A:

First of all, some of the commands are used to make archives - ie. a file that contain other files, often with directory-structure, ownership, permissions and dates.  The most common of these are ar (used when creating libraries), tar (TapeARchive) and cpio (CoPyInOut).
Then we have some commands that are used to compress files - ie. making the file take-up less space on the disk.  Compressing can also be done to archives.  The most common compression-programs are gzip, bzip2, xz, 7zip... as well as the two older ones, compress and compact.
This is very much in accordance to the "Unix-philosophy", where each command does only one thing (but does it well)... here, either creates archives or compress a file - but not both.  Of course one command may call another, as tar may call gzip or bzip2.
For Windows it's more common to make programs that combine related tasks - or rather, for the user seemingly related tasks...  Like making and archive and compressing it - even though these are very different tasks.  Consequently we also have some tools under Unix/Linux to handle - and sometimes create - such archives.  zip, rar and arj are examples of such archives, that are more or less supported under Linux.  These typically do both compressing and archiving at once (e.g. zip first compress the files, then makes an archive of the compressed files).
rar and zip do AFAIK know support some sort of "encryption" and password, but these are rather poor.  You probably would be better off (as well as more correctly Unix-wise) to use a separate tool for encrypting and/or password-protecting the files - perhaps gnupg or truecrypt?
At least zip, rar and tar support creation of archives of multiple parts.  However an other acceptable "Unix-way" to do it; would be to use split either on the uncompressed archive (tar or cpio) and compress each part separately, or on the compressed (eg. with bzip2) file - and later using cat to merge the parts.  Splitting the compressed archive would perhaps be best, as after re-merging, the compress-program (eg. bzip2) would detect any errors.  Although compressing each part individually, would ensure that the other parts could be recovered (with most of their files) if one part was damaged.

