Linux File and Folder Compression and Extraction

Compress

To compress a whole Linux directory, use the tar command:

 tar -zcvf archive.tar.gz directory-path

 Options used above:
-z : Compress archive using gzip program
-c: Create archive
-v: Verbose i.e display progress while creating archive
-f: Archive File name

The -v verbose options will diplay the list of files as they are added to the archive, so you would see a scrolling list of files as the folder is being compressed into an archive file.

If you're rather not see this, you can remove the verbose option.

Extract

To extract an archive created with tar, use the same command with a different option

 tar -zxvf archive.tar.gz

Notice that instead of the -c "create" option, we use the -x "extract" option.

This command will extract the archive to the current directory.