Bash 5 reference · Text and System Tools
tar (Linux command)
Create, list and extract archives, usually gzip-compressed .tar.gz files, preserving directory structure and permissions.
Bash 5
Syntax
tar -czf ARCHIVE.tar.gz PATHS tar -tzf ARCHIVE tar -xzf ARCHIVE [-C DIR]
Parameters
| Parameter | Description |
|---|---|
-c / -x / -t |
Create / extract / list. |
-z / -J |
gzip / xz compression. |
-f FILE |
Archive file. |
-C DIR |
Change to DIR (extract into it). |
--exclude PATTERN |
Skip matching files. |
Examples
mkdir -p app/logs; echo hi > app/main.sh; echo x > app/logs/a.log
tar -czf app.tgz --exclude='*.log' app
tar -tzf app.tgz | sort
Output
app/ app/logs/ app/main.sh
Run this on your computer — see “Get Started” for setup.
mkdir src; echo data > src/f; tar -czf s.tgz src
mkdir out; tar -xzf s.tgz -C out; cat out/src/f
Output
data
Run this on your computer — see “Get Started” for setup.
Related
find· Find files and directories by name, type, size, age or permissions, and act on them with -exec, -delete or xargs.- Bash Archives, Compression and Checksums · tutorial