---
# System prepended metadata

title: Linux - compress tools
tags: [linux, tar]

---

# Linux - compress tools

###### tags: `linux` `tar`

```
# .gz
gzip [options] <file directory>

!!! default is to compress without -d

-d  decompress
-r  recurse
-c  stdout, source file not deleted. ex. gzip -c file1 > file1.gz
-1..9  compress rate low(1) to high(9)


# .bz2
bzip2 [options] <file directory>

-c  stdout. ex. bzip -c file1 > file1.bz
-d  decompress
-k  no delete source
-1..9  compress rate low(1) to high(9)


# .zip (zip and unzip)
zip [options] <target zip file> <file directory>

-D  without dir name
-F  try to fix broken zip file
-P  encrypt the zip file
-r  recurse
-T  test zip file broken or not
-z
-1..9  compress rate low(1) to high(9)
-n <sub filename> file name not include sub filename
-i <include file> include file name. ex. *.bmp
-x <not include file> exclude file name. ex. *.jpg

unzip [options] <zipped file> <file directory>
-d <target path> decompress to path
-l   show zipped file info
-p   compress to pipe
-t   test zipped broken or not
-v   show decompress info
-x <file>  not decompress file
-Z   same as zipinfo


# .tar
tar -xvf <tar file name>
tar -cf <tar file name> <source file directory>

-j  use bzip2 to compress/decompress
-p  restore file premission
-P  use absolution path
-z  use gzip to compress/decompress
-Z  use compress to compress/decompress
```