Monday 14 October 2013

ELA_08_Compression_Utilities

A tar file is a collection of several files and/or directories in one file. This is a good way to create backups and archives.
Some of tar's options include:
  • -c — create a new archive
  • -f — when used with the -c option, use the filename specified for the creation of the tar file; when used with the -x option, unarchive the specified file
  • -t — show the list of files in the tar file
  • -v — show the progress of the files being archived
  • -x — extract files from an archive
  • -z — compress the tar file with gzip
  • -j — compress the tar file with bzip2
To create a tar file, enter:
tar -cvf filename.tar directory/file

In this example, filename.tar represents the file you are creating and directory/file represents the directory and file you want to put in the archived file.
You can tar multiple files and directories at the same time by listing them with a space between each one:
tar -cvf filename.tar /home/mine/work /home/mine/school

The above command places all the files in the work and the school subdirectories of /home/mine in a new file called filename.tar in the current directory.
To list the contents of a tar file, enter:
tar -tvf filename.tar

To extract the contents of a tar file, enter:
tar -xvf filename.tar

This command does not remove the tar file, but it places copies of its unarchived contents in the current working directory, preserving any directory structure that the archive file used. For example, if the tarfile contains a file called bar.txt within a directory called foo/, then extracting the archive file results in the creation of the directory foo/ in your current working directory with the file bar.txt inside of it.
Remember, the tar command does not compress the files by default. To create a tarred and bzipped compressed file, use the -j option:
tar -cjvf filename.tbz file

tar files compressed with bzip2 are conventionally given the extension .tbz; however, sometimes users archive their files using the tar.bz2 extension.
The above command creates an archive file and then compresses it as the file filename.tbz. If you uncompress the filename.tbz file with the bunzip2 command, the filename.tbz file is removed and replaced with filename.tar.
You can also expand and unarchive a bzip tar file in one command:
tar -xjvf filename.tbz

To create a tarred and gzipped compressed file, use the -z option:
tar -czvf filename.tgz file
tar files compressed with gzip are conventionally given the extension .tgz.
This command creates the archive file filename.tar and compresses it as the file filename.tgz. (The file filename.tar is not saved.) If you uncompress the filename.tgz file with the gunzip command, the filename.tgz file is removed and replaced with filename.tar.
You can expand a gzip tar file in one command:
tar -xzvf filename.tgz

No comments :

Post a Comment