# Compressing and archiving

## Compression types

It's to make data smaller and making it easier to transfer also keep the integrity

There are two types of compression: **lossy** and **lossless**

Basically lossy will not keep the integrity but make files significantly smaller compared to lossless, but it will ensure the integrity of the file and make it slightly smaller

## T-archiving

To compress files we should **archive** them in advance, in linux we can use `tar` command to achieve this.

Let’s say we have some files: `myscript.sh, mysecret.txt, mynotes.txt`

```bash
$ tar -cvf Packed.tar myscript.sh, mysecret.txt, mynotes.txt
 myscript.sh
 mysecret.txt
 mynotes.txt
```

Flags: `c` - create, `v` - verbose(optional), `f` - write to the file after the flag

```bash
$ tar -tvf Packed.tar
-rwxr-xr-x 1 vix vix 22311 Dec 1 2025 18:00 myscript.sh
-rw-r----- 1 vix vix 8791  Dec 1 2025 18:00 mysecret.txt
-rw-r----- 1 vix vix 3992  Dec 1 2025 18:01 mynotes.txt
```

Here we see another flg `t` we use tarball to list the file out without extracting them, if you want ot extract them add a `x` flag

```bash
$ tar -xvf Packed.tar 
 myscript.sh
 mysecret.txt
 mynotes.txt
```

## Compressing files

To compress the files we can use these:

| Tool  | Extensions    | Speed     | Compression Ratio |
| ----- | ------------- | --------- | ----------------- |
| gzip  | .tar.gz, .tgz | Fastest   | Good              |
| bzip2 | .tar.bz2      | Slow      | High              |
| xz    | .tar.xz       | Very Slow | Best              |
| zip   | .zip          | Fast      | Good              |

### gzip

```bash
$ gzip/bzip2/xz/zip/etc Packed.* #zip file
$ ls
 Packed.tar.(gz)
$ gunzip Packed.* #unzip file
```

## Creating Physical copies of storage devices

Here we will use `dd` command to make a bit-by-bit copy of a file, file system, or entire hard drive. (including deleted files)

It’s useful when need to do recovery or having backups

```bash
$ dd if=input_file of=output_file
```

Note that `dd` will copy the exact size as the input file


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vix-w1zzer.gitbook.io/vixwizzer/notes/linux/compressing-and-archiving.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
