Archiving/compressing

Archiving and compressing

There are a number of options for archiving and compressing directories and files at HPC2N.

tar   (more information)

This program saves many files together into a single archive file, and it also restores individual files from the archive. Automatic archive compression/decompression options exists, as well as special features that allow tar to be used for incremental and full backups. The command tar --help will give the format (defaults to gnu). This is generally only important for files larger than 8 GB.

Examples:

archive a file

$ tar cvf myfile.tar myfile.txt 
myfile.txt

archive and compress a file

$ tar cvfz myfile.tar.gz myfile.txt 
myfile.txt

list contents of a tar file

$ tar tvf myfile.tar
-rwxr-xr-x username/folk 23717 2009-10-02 15:48:48 myfile.txt

extract contents of a tar file

$ tar xvf myfile.tar
myfile.txt

extract contents of gzipped tar-archive

$ tar xvfz myfile.tar.gz 
myfile.txt

archive and compress all files in a directory to a single tar file

$ tar cvfz mydir.tar.gz C/
C/
C/hello
C/hello.c
C/hello_submit

archive and compress all files of a certain type (here .c) to a single tar-file(only those in current directory and below)

$ tar cvfz myfile.tar.gz *.c
calc.c
converting.c
hello.c

gzip   (more information)

Compression utility designed as a replacement for compress, with much better compression and no patented algorithms. The standard compression system for all GNU software.

Examples:

compress a file (also removes the uncompressed file)

$ gzip myfile.txt

uncompress a file (also removes the compressed file)

$ gunzip myfile.txt.gz 

bzip2   (more information)

Strong, lossless data compressor based on the Burrows-Wheeler transform. Also available as a library.

Examples:

compress a file (also removes the uncompressed file)

$ bzip2 myfile.txt

uncompress a file (also removes the compressed file)

$ bunzip2 myfile.txt.bz2 

zip   (more information)

Simple compression and file packaging utility. Note that the maximum size limit of a zip file is 4GB and if this size limit is exceeded, the file becomes prone to corruption. This further leads to failure of the extraction process and inaccessibility of your data.

Zip examples:

compressing myfile.txt

$ zip myfile.zip myfile.txt 
  adding: myfile.txt (deflated 57%)

uncompressing myfile.zip (if the file already exists, zip will ask if you want to replace or rename)

$ unzip myfile.zip
Archive:  myfile.zip
  inflating: myfile.txt              

compress all files in one directory to a single archive file

$ zip -r mydir.zip C/
  adding: C/ (stored 0%)
  adding: C/hello (deflated 66%)
  adding: C/hello.c (deflated 3%)
  adding: C/hello_submit (deflated 24%)

compress all files of a certain type in the current directory (and in directories under this) to a single archive file
(in this case all .c files)

$ zip -r my_c_files.zip . -i \*.c
  adding: hello.c (deflated 3%)
  adding: C/hello.c (deflated 3%)
  adding: converting.c (deflated 31%)
  adding: calc.c (deflated 5%)

Archiving/compressing on WIndows

There are a number of Windows programs using the same formats. These are a few of the more popular ones:

  • 7-Zip
    Free Windows software package that can handle all the above formats.
  • WinZip
    Commercial Windows software package that can handle all the above formats.
  • WinRAR
    Commercial Windows software package that can handle all the above formats.
Updated: 2017-05-22, 17:38