The Three Musketeers of File Extraction in Linux: Are You Familiar with Them?
1. tar
1.1 <span>tar</span> Command Introduction
<span>tar</span> is a Linux archiving tool responsible for packaging files, but it does not compress! It works in conjunction with tools like <span>gzip</span>, <span>bzip2</span>, and <span>xz</span> to achieve compression.
1.2 <span>tar</span> Command Options
| Option | Meaning |
|---|---|
| -c | Create an archive file |
| -x | Extract an archive file |
| -v | Show progress |
| -f | Specify filename (must be the last option) |
| -z | Use gzip compression/decompression (.tar.gz) |
| -j | Use bzip2 compression/decompression (.tar.bz2) |
| -J | Use xz compression/decompression (.tar.xz) |
| -t | List contents |
| -C | Specify directory |
1.3 <span>tar</span> Common Examples
# Extract
tar -xzvf demo.tar.gz
# Extract to specified directory
tar -xzvf demo.tar.gz -C /home/xxx
# Archive
tar -cvf demo.tar file1
# Compress to .gz
tar -czvf demo.tar.gz file1
# List contents
tar -tzvf demo.tar.gz
2. unzip
2.1 <span>unzip</span> Command Introduction
<span>unzip</span> is used to extract <span>.zip</span> format files and is one of the essential tools in Linux.
2.2 <span>unzip</span> Installation
# CentOS
yum install unzip
# Ubuntu
apt install unzip
2.3 <span>unzip</span> Common Options
| Option | Meaning |
|---|---|
| -l | List contents without extracting |
| -d | Specify extraction directory |
| -o | Overwrite files |
| -n | Do not overwrite files |
| -q | Quiet mode |
| -P | Specify password |
| -j | Do not preserve directory structure during extraction |
2.4 <span>unzip</span> Examples
# Extract
unzip demo.zip
# Extract to specified directory
unzip demo.zip -d /home/xxx
# List contents
unzip -l demo.zip
# Extract with password
unzip -P password demo.zip
3. unrar
3.1 <span>unrar</span> Command Introduction
<span>unrar</span> is used to extract <span>.rar</span> format files, solving the problem of extracting RAR files in Linux.
3.2 <span>unrar</span> Installation
# CentOS
yum install unrar
# Ubuntu
apt install unrar
3.3 <span>unrar</span> Common Options
| Option | Meaning |
|---|---|
| e | Extract to current directory |
| x | Extract to specified directory |
| l | List contents |
| p | Specify password |
| o+ | Overwrite files |
| o- | Do not overwrite files |
3.4 <span>unrar</span> Practical Examples
# Extract to current directory
unrar e file.rar
# Extract to specified directory
unrar x file.rar /home/xxx
# View contents
unrar l file.rar
# Extract password-protected file
unrar p -password file.rar