Zip Or Compress Directory On Linux

Dec 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

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.