Compress and extract TAR files on linux

How to compress and extract TAR files on linux with gzip easily.

SNP 009 #65B Filed cmd

To compress just use this.

shell
tar -czvf archive-name.tar.gz /directory-path-or-file

Options are:

  • c: create
  • z: compress with gzip
  • v: verbose mode
  • f: specify filename

To extract a compressed file just use this.

shell
tar -xzvf archive-name.tar.gz

Or you can specify the directory where you want to extract.

shell
tar -xzvf archive-name.tar.gz -C /var/www