# Compress / Decompress files

### 0. Requirement packages

```
apt install tar zip unzip gzip
```

### 1. Compress

* Compress single file into `.tar.gz`&#x20;

```
tar -zcvf telegraf-legacy.log.tar.gz telegraf.log --totals --verbose
```

* Compress a directory into `.tar.gz`&#x20;

```
tar -zczf monit-5.26.0.tar.gz monit-5.26.0/ --totals --verbose
```

After that if you want **remove original file** then use with option `--remove-files`

* Compress single file into `.gz`&#x20;

```
# From tocdo.log --> tocdo.gz (dropped original file)

gzip tocdo.log 
```

* Compress single file into `.zip`

```
# From tocdo.log --> tocdo.zip (dropped original file)

zip x tocdo.log
```

### 2. Decompress&#x20;

```
tar -xzf foo.tar.gz --totals --verbose
```

```
unzip -a x.zip
```
