Linux shell compress a directory

GNU tar command is best for this work.
=> Create the archive
=> Compress the archive

Use tar command:
tar -zcvf archive-name.tar.gz directory-name

  • -z: Compress archive using gzip
  • -c: Create archive
  • -v: Verbose
  • -f: Archive File name

Compress this directory /home/ppuk:
$ tar -zcvf ppuk01102014.tar.gz /home/ppuk

This will create ppuk01102014.tar.gz in current directory.

To uncompress ppuk01102014.tar.gz in the current directory:
$ tar -zxvf ppuk01102014.tar.gz


  • -x: Extract files

To extract this directory into /tmp then:
$ tar -zxvf ppuk01102014.tar.gz -C /tmp
$ cd /tmp
$ ls -

Author: Purple Panda UK

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *

× 9 = sixty three