# Archive

File compression is a fundamental task in managing and transferring data efficiently on a Linux system.

An archive file is a compressed file that contains one or more files bundled together for more accessible storage and portability.

<figure><img src="https://921544542-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRQTWHUNVZ5tIxQJXclF%2Fuploads%2Fl4LRcw45aXTROachAmlt%2F0_fQgW7tgEy5ebQwHT.png?alt=media&#x26;token=f4286fe9-2445-4d4f-b6a7-d3ebd53fb842" alt=""><figcaption><p>Archive</p></figcaption></figure>

Archiving commands in Linux are tools used to package and compress one or multiple files or directories into a single archive file.

The most commonly used archiving commands in Linux include tar, gzip, zip, and rar.

## Understanding Archiving Commands in Linux <a href="#id-3442" id="id-3442"></a>

Archiving commands in Linux are a set of tools used to create, manage, and extract archive files.&#x20;

These tools allow users to package one or more files or directories into a single archive file, compress the data, and store it in an organized and efficient manner.

They help to reduce the overall size of files and directories, making them easier to transfer and store.

### common archiving commands in Linux <a href="#id-7d9a" id="id-7d9a"></a>

1. tar

Used to create, manage, and extract tar archives. Tar stands for “tape archive,” which refers to its origins as a tool for backing up data to tape drives.

2. gzip

Used to compress and decompress files using the gzip compression algorithm. Gzip is commonly used in conjunction with tar to create tarballs, which are tar archives that have been compressed with gzip.

3. zip

Used to create, manage, and extract zip archives. Zip is a popular archive format that is supported by many operating systems.

4. rar

Used to create, manage, and extract rar archives. Rar is a proprietary archive format that supports compression, spanning, and error recovery.

## Basic Archiving Commands <a href="#b1da" id="b1da"></a>

1. tar command

```bash
tar -cvf file.tar /path/to/folder
```

This command creates a tar archive called `file.tar` from the contents of the directory located at `/path/to/folder`

```bash
tar -xvf file.tar
```

This command extracts the contents of the `file.tar` archive into the current directory.

2. gzip commands

```bash
gzip file.txt
```

This command compresses a file called `file.txt` and replaces it with a compressed file called `file.txt.gz`.

```bash
gunzip file.txt.gz
```

This command decompresses a file called `file.txt.gz` and replaces it with a decompressed file called `file.txt`.

```bash
zcat file.txt.gz
```

This command displays the contents of a compressed file called `file.txt.gz` on the terminal without extracting it.

```bash
zless file.txt.gz
```

This command allows you to view the contents of a compressed file called `file.txt.gz` in a more user-friendly way.

3. zip commands

```bash
zip archive.zip file1.txt file2.txt
```

This command creates a new zip archive called `archive.zip` and adds two files called `file1.txt` and `file2.txt` to it.

```bash
unzip archive.zip
```

4. rar commands

```bash
rar a archive.rar file1.txt file2.txt
```

This command creates a new rar archive called `archive.rar` and adds two files called `file1.txt` and `file2.txt` to it.

```bash
unrar x archive.rar
```

This command extracts the contents of the `archive.rar` file into the current directory.

{% hint style="info" %}
For more archive command options you can use man page to get all options for all compression methods.
{% endhint %}


---

# 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://devops-3.gitbook.io/devops/docs/module-1-linux-introduction/archive.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.
