Zip Or Compress Directory On Linux

December 12, 2017
tar -czvf [FILENAME].tar.gz [DIRECTORY]

The following tar command will:

  • -c: create a new archive
  • -z: gzip
  • -f: use archive file
  • -v: verbose - list all files archived (optional)
tar -czvf [FILENAME].tar.gz [DIRECTORY]

The following extra parameters are useful:

  • -p: preserve permission
  • --exclude: exclude files

Compress directory with exclude file extension.

tar -czvf [FILENAME].tar.gz [DIRECTORY] --exclude "*.pyc"

Compress directory with exclude sub directory.

tar -czvf [FILENAME].tar.gz [DIRECTORY] --exclude "tmp"

Compress directory with multiple excludes.

tar -czvf [FILENAME].tar.gz [DIRECTORY] --exclude "*.pyc" --exclude "tmp"

Extract .tar.gz.

tar -zxf [FILENAME].tar.gz
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.