Update 11-tar.md
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# 📦 Linux Compression & Archiving Cheatsheet
|
# Linux Compression & Archiving Cheatsheet
|
||||||
|
|
||||||
## 🔧 Tar Command Basics
|
## Tar Command Basics
|
||||||
|
|
||||||
The `tar` command is used to create, extract, and manage archive files.
|
The `tar` command is used to create, extract, and manage archive files.
|
||||||
|
|
||||||
@@ -10,16 +10,20 @@ The `tar` command is used to create, extract, and manage archive files.
|
|||||||
tar [options] [archive_name.tar] [file(s)/directory]
|
tar [options] [archive_name.tar] [file(s)/directory]
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🛠 Create a `.tar` Archive
|
---
|
||||||
|
|
||||||
|
### Create a `.tar` Archive
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -cf archive_file.tar file1 file2 dir1
|
tar -cf archive_file.tar file1 file2 dir1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Options:**
|
||||||
|
|
||||||
* `-c`: Create a new archive
|
* `-c`: Create a new archive
|
||||||
* `-f`: Specify the archive file name
|
* `-f`: Specify the archive file name
|
||||||
|
|
||||||
### 🛠 Create with Verbose Output
|
### Create with Verbose Output
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -cvf archive_file.tar file1 file2 dir1
|
tar -cvf archive_file.tar file1 file2 dir1
|
||||||
@@ -27,12 +31,14 @@ tar -cvf archive_file.tar file1 file2 dir1
|
|||||||
|
|
||||||
* `-v`: Verbose mode (shows progress)
|
* `-v`: Verbose mode (shows progress)
|
||||||
|
|
||||||
### 📂 Extract a `.tar` Archive
|
### Extract a `.tar` Archive
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xf archive_file.tar
|
tar -xf archive_file.tar
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xvf archive_file.tar
|
tar -xvf archive_file.tar
|
||||||
```
|
```
|
||||||
@@ -41,11 +47,11 @@ tar -xvf archive_file.tar
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🗜 Gzip Compression
|
## Gzip Compression
|
||||||
|
|
||||||
**Gzip** (GNU zip) is a fast, commonly used compression tool.
|
**Gzip** (GNU zip) is a fast and widely used compression tool.
|
||||||
|
|
||||||
### 🔧 Create `.tar.gz` Archive
|
### Create a `.tar.gz` Archive
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -czf archive_file.tar.gz file1 file2 dir1
|
tar -czf archive_file.tar.gz file1 file2 dir1
|
||||||
@@ -53,29 +59,31 @@ tar -czf archive_file.tar.gz file1 file2 dir1
|
|||||||
|
|
||||||
* `-z`: Compress using gzip
|
* `-z`: Compress using gzip
|
||||||
|
|
||||||
### 🔧 Verbose Creation
|
### Verbose Creation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -czvf archive_file.tar.gz file1 file2 dir1
|
tar -czvf archive_file.tar.gz file1 file2 dir1
|
||||||
```
|
```
|
||||||
|
|
||||||
### 📂 Extract `.tar.gz`
|
### Extract `.tar.gz`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xzf archive_file.tar.gz
|
tar -xzf archive_file.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xzvf archive_file.tar.gz
|
tar -xzvf archive_file.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🗜 Bzip2 Compression
|
## Bzip2 Compression
|
||||||
|
|
||||||
**Bzip2** offers better compression than gzip but is slower.
|
**Bzip2** provides better compression than gzip but at the cost of speed.
|
||||||
|
|
||||||
### 🔧 Create `.tar.bz2` Archive
|
### Create a `.tar.bz2` Archive
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -cjf archive_file.tar.bz2 file1 file2 dir1
|
tar -cjf archive_file.tar.bz2 file1 file2 dir1
|
||||||
@@ -83,29 +91,31 @@ tar -cjf archive_file.tar.bz2 file1 file2 dir1
|
|||||||
|
|
||||||
* `-j`: Compress using bzip2
|
* `-j`: Compress using bzip2
|
||||||
|
|
||||||
### 🔧 Verbose Creation
|
### Verbose Creation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -cjvf archive_file.tar.bz2 file1 file2 dir1
|
tar -cjvf archive_file.tar.bz2 file1 file2 dir1
|
||||||
```
|
```
|
||||||
|
|
||||||
### 📂 Extract `.tar.bz2`
|
### Extract `.tar.bz2`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xjf archive_file.tar.bz2
|
tar -xjf archive_file.tar.bz2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xjvf archive_file.tar.bz2
|
tar -xjvf archive_file.tar.bz2
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🗜 XZ Compression
|
## XZ Compression
|
||||||
|
|
||||||
**XZ** provides the best compression ratios but is the slowest.
|
**XZ** offers the best compression ratio but is the slowest option.
|
||||||
|
|
||||||
### 🔧 Create `.tar.xz` Archive
|
### Create a `.tar.xz` Archive
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -cJf archive_file.tar.xz file1 file2 dir1
|
tar -cJf archive_file.tar.xz file1 file2 dir1
|
||||||
@@ -113,31 +123,33 @@ tar -cJf archive_file.tar.xz file1 file2 dir1
|
|||||||
|
|
||||||
* `-J`: Compress using xz
|
* `-J`: Compress using xz
|
||||||
|
|
||||||
### 🔧 Verbose Creation
|
### Verbose Creation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -cJvf archive_file.tar.xz file1 file2 dir1
|
tar -cJvf archive_file.tar.xz file1 file2 dir1
|
||||||
```
|
```
|
||||||
|
|
||||||
### 📂 Extract `.tar.xz`
|
### Extract `.tar.xz`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xJf archive_file.tar.xz
|
tar -xJf archive_file.tar.xz
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -xJvf archive_file.tar.xz
|
tar -xJvf archive_file.tar.xz
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📊 Compression Format Comparison
|
## Compression Format Comparison
|
||||||
|
|
||||||
| Feature | `gzip` | `bzip2` | `xz` |
|
| Feature | gzip | bzip2 | xz |
|
||||||
| ------------------- | ------------ | ---------- | --------- |
|
| ------------------- | ----------- | ---------- | --------- |
|
||||||
| Compression Speed | Fast | Slow | Slowest |
|
| Compression Speed | Fast | Slow | Slowest |
|
||||||
| Decompression Speed | Fast | Slower | Moderate |
|
| Decompression Speed | Fast | Slower | Moderate |
|
||||||
| Compression Ratio | Good | Better | **Best** |
|
| Compression Ratio | Good | Better | Best |
|
||||||
| File Extension | `.tar.gz` | `.tar.bz2` | `.tar.xz` |
|
| File Extension | `.tar.gz` | `.tar.bz2` | `.tar.xz` |
|
||||||
| Common Use | Web, general | Backups | Archival |
|
| Common Use | General/Web | Backups | Archival |
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user