Archives & CompressionCLI Reference
$tar
Archive multiple files into a single tape archive (.tar or .tar.gz).
Syntax DefinitionPOSIX standard
tar [OPTIONS] [ARCHIVE-FILE] [FILE...]Try `tar` Live in Interactive Sandbox
Zero-install client simulation with real-time feedback.
bash — terminal
AST Sandbox (Free)
Overview & How tar Works
`tar` (Tape Archive) bundles multiple files and entire directory structures into a single uncompressed archive file, or compresses them on the fly using gzip (`.tar.gz`), bzip2 (`.tar.bz2`), or xz.
Common Flags & Command Options
| Flag / Option | Description |
|---|---|
| -c, --create | Create a new tar archive. |
| -x, --extract | Extract files from an existing archive. |
| -z, --gzip | Compress or decompress archive using gzip algorithm. |
| -v, --verbose | Verbosely list files processed. |
| -f, --file [ARCHIVE] | Use archive file specified. |
| -t, --list | List the contents of an archive without extracting it. |
Practical Real-World Examples
Example #1Compress a folder into a .tar.gz archive
tar -czvf backup.tar.gz /home/user/projectsCreates a compressed archive named backup.tar.gz containing all files in projects.
Sample Output:
backup.tar.gz created successfully.Example #2Extract a .tar.gz archive
tar -xzvf backup.tar.gz -C /tmpExtracts all contents of backup.tar.gz into the /tmp directory.
Frequently Asked Questions
How do you remember the tar flags for extracting vs creating?
Think **-czvf** for **C**reate Zip Verbose File, and **-xzvf** for e**X**tract Zip Verbose File.