How to Tar Untar and Zip Files

Published on: October 29, 2013
Difficulty: Very Easy

This article covers how to Tar Untar and Zip Files.

These commands can be run from within SSH to tar or untar a tarball file. These files are typically used in packaged backups or a directory that has been compressed.

Tar

These commands will compress the selected directory into a tarball file, which will be located within the original directory.

To compress a directory into a tar file (.tar):
tar -xvf FILENAME.tar DIRECTORY/
To compress a directory into a gzip tar file (.tgz or .tar.gz):
tar -czvf FILE.tar.gz DIRECTORY/
To compress a directory into a bzip2 tar file (.tbz or .tar.bz2):
tar -jxvf FILE.tar.bz2 DIRECTORY/

Untar

These commands will extract the tarball file into the current directory it is located in.

To uncompress a tar file (.tar):
tar xvf FILE.tar
To uncompress a gzip tar file (.tgz or .tar.gz):
tar xvzf FILE.tar.gz
To uncompress a bzip2 tar file (.tbz or .tar.bz2):
tar xvjf FILE.tar.bz2

Zip and Unzip

To compress the selected directory into a zip file, which will be located within the original directory:
zip -r fFILE.zip DIRECTORY/
To extract the selected zip file, which will be uncompressed into the directory the zip is located in:
unzip FILE.zip

Additional Notes

If you wish to extract the tarball file to a specific directory, adding the following to the end of the command will extract it to the specified location:

-C /DIRECTORY/


Back To Top