Friday 20 March 2009

Making and extracting TAR archives

Here are just a few helpful hints about tar and gzip files.

The TAR file format is popular in Unix/Linux and the TAR program is used to stick many files together into an archive - one file. That file can then be gzipped to become compressed.

To extract a TAR archive:

tar -xvf example_file.tar

The 'x' argument means eXtract, 'v' is for verbose (information about what is happening is displayed) and 'f' stands for filename which you provide after the arguments.

To TAR a folder:

tar -cvf example_name.tar ./folder_to_tar

The 'c' argument means create. This command will tar the folder "folder_to_tar" into the archive (file) "example_name.tar".

A good way to remember these tar commands is to realise that the argument letters are all next to each other - the C, V and F form a triangle on your keyboard (qwerty). And X stands for extract. Simples.

On another point, you can compress the tar archive on the fly by adding the argument 'x' within the argument list like so: -xzvf. Just don't put any argument after the 'f' flag or it will think that letter is the filename and cause you errors.

Tars are good to gzip if you forget to use the 'z' flag in the argument list. To gzip, compress, the tar file if you want using this command:

gzip example_name.tar

This will replace the tar in the directory with the popular .tar.gz file type: example_name.tar.gz.

To extract the .tar.gz archive:

gunzip example_name.tar.gz

This will put the tar file back in the directory as it was before.

There you go. Have fun in your console.

No comments:

Post a Comment