Command Line

How do you compress a folder using the Tar Command?

Every time I need to compress a file, I google the answer. I am quite tired of that and decided to write myself mine. Here’s a good tutorial about compressing files using the Tar Command.

1 Go to the location of the folder

$ cd /location

2 Use the tar command to compress the file

The important aspect of the command below is the -c which translates to compress

$ tar -zcvf a folder.tar.gz system
system/
system/popups/
system/popups/photos/
system/popups/photos/000/
system/popups/photos/000/000/
system/popups/photos/000/000/001/
system/popups/photos/000/000/001/photo_thumb/
system/popups/photos/000/000/001/photo_thumb/Free-Phyto.jpg
system/popups/photos/000/000/001/photo_main/
system/popups/photos/000/000/001/photo_main/Free-Phyto.jpg
system/popups/photos/000/000/001/original/
system/popups/photos/000/000/001/original/Free-Phyto.jpg

Voila! A compressed file!

$ ls
-rw-rw-r--  1 group group 190M Nov  4 13:25 folder.tar.gz

How to Extract a Tar Compressed File

In the last tutorial, we compressed a folder using the Tar command. Here’s another for extracting from a tar compressed file.

1 Go to the location of the Tar compressed file

cd /location

2 Use the Tar command

The important aspect of the command below is the -x which translates to extract

$ tar -zxvf folder.tar.gz 
system/
system/popups/
system/popups/photos/
system/popups/photos/000/
system/popups/photos/000/000/
system/popups/photos/000/000/001/
system/popups/photos/000/000/001/photo_thumb/
system/popups/photos/000/000/001/photo_thumb/Free-Phyto.jpg
system/popups/photos/000/000/001/photo_main/
system/popups/photos/000/000/001/photo_main/Free-Phyto.jpg
system/popups/photos/000/000/001/original/
system/popups/photos/000/000/001/original/Free-Phyto.jpg
ls -lah
drwxrwxr-x  9 group group 4.0K Nov  4 10:12 system

Bookmark this Tutorial for reading. Thanks!