> For the complete documentation index, see [llms.txt](https://olb.gitbook.io/linux-essentials-certification/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olb.gitbook.io/linux-essentials-certification/3.the-power-of-command-line/3.1-archiving.md).

# 3.1 Archiving

**Weight 2**\
Key knowledge areas

* Files, directories
* Archives, compression

Partial list of the used files, terms and utilities

* tar
* Common tar options
* gzip, bzip2, xz
* zip, unzip

***

## Introduction

* Compression is used to reduce amount of space needed to store a file
* Compression works by replacing repetitive patterns in data
* Compression comes in two varieties, lossless (text data) and lossy (video,audio,images)
* Archiving tools are used to bundle up files and directories into a single file
* Archiving tool : `tar`

## Compression tools

* `bzip2` /`bunzip2` and tools like `bzcat, bzgrep, bzdiff`
* `gzip` / `gunzip` and tools like `zcat, zgrep, zdiff`
* `xz` / `unxz` and tools like `xzcat, xzgrep, xzdiff`
* `zip` / `unzip`

## Archiving Tools

* `tar` : abreviation of 'tape archive'
* `tar -cf filename.tar filename` : c = create, f = filename
* `tar -tf filename.tar` : list tar ball content
* `tar -xf filename.tar` : desarchivage
* `tar -czf gzip.tar.gz bigfile bigfile2 bigfile3` : tar + gzip compression
* `tar -cjf bzip2.tar.bz2 bigfile bigfile2 bigfile3` : tar + bzip2 compression
* `tar -cJf xz.tar.xz bigfile bigfile2 bigfile3` : tar + xz compression
* `tar -uf plain.tar bigfile4` : use `-u` to add a file to a tar ball
* `tar -uf plain.tar.gz bigfile4` : error cannot update an archive
* `zip -r zipfile.zip filename` : zip a file
* `unzip zipfile.zip` : unzip a file
