Decompressing files:

We'll start with .tar This is a file that has been compressed using the tar command in linux. To decompress a tar file issue the following command:

tar -xvf filename.tar

So what do those flags mean?

-x This mean extract the file.
-v This means verbose, it tells you what it's doing.
-f This is the file flag, the filename directly follows this flag.

The .tar is now extracted to a directory that was made in the current directory.


What about tar.gz? This is a tar file that has been sent through gzip, another compression utility, as well. To decompress this issue:

tar -zxvf filename.tar.gz

The extra flag here is z which means:

z This means run it through gzip before running it through tar.


What about .tar.bz2 This is like .tar.gz, except it was put through bzip2 instead of gzip. To decompress this issue:

bzip2 -d filename.tar.bz2

This uses the bzip2 command with the (-d) decompress flag. This decompresses the bzip version and leaves a file called filename.tar in the directory. To decompress this see .tar above.


I see .tgz, how do I use this?

.tgz is just the same as .tar.gz .


What about .zip I use winzip in windows, what about linux?

Easy in linux just type:

unzip filename.zip


Compressing files:

To make a .zip use the command:

zip -r zipname path

-r means recursive which means that if there are subdirectories in the directory it will grab those as well.
zipname: is the name of the file you want at the end, ie myzip.zip
path: is the path to the directory you want to zip up. This can be relative or absolute.
relative path: say you are in your home directory /home/foouser and want to zip up the subdirectory mail. If you use a relative path you would put zip -r mails.zip mail .
absolute path: for absolute you would use zip -r mails.zip /home/foouser/mail .


To make a .tar

Add by files:

So you want to add specific files? use this command:

tar -cv -f filename.tar file1 file2 file3 ..... fileN

-c This is the flag that tells tar you are creating a new .tar archive.
-v Verbose so it tells you what it is doing.
-f This once again tells tar that the filename is the next name it sees.

filename.tar You may make filename whatever you want to name the file.

file1 through fileN the names of the N files you want to add. Use as many files as you want.

ex: tar -cv -f stories.tar first.doc second.txt nice.wri cup.zip wheel.exe

Add by directory:

Say you want to add all the files in a directory:

tar -cv -f filename.tar path

path can once again be absolute or relative.

ex:
Absolute tar -cv -f filename.tar /home/foouser/mail
Relative tar -cv -f filename.tar mail if I happened to be in the /home/foouser directory.


Want to make a .tar.gz?

Follow the instructions for making a .tar and use:

gzip filename.tar

This makes the file a .tar.gz but compressed.


Want to make a .tar.bz2?

Follow the instructions for making a .tar and issue:

bzip2 filename.tar

This makes the file a .tar.bz2 and compresses it as well.


- author jkrohn