Online Linux Terminal Logo
OnlineLinuxTerminal
Archives & CompressionCLI Reference

$tar

Archive multiple files into a single tape archive (.tar or .tar.gz).

Syntax DefinitionPOSIX standard
tar [OPTIONS] [ARCHIVE-FILE] [FILE...]
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `tar` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

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 / OptionDescription
-c, --createCreate a new tar archive.
-x, --extractExtract files from an existing archive.
-z, --gzipCompress or decompress archive using gzip algorithm.
-v, --verboseVerbosely list files processed.
-f, --file [ARCHIVE]Use archive file specified.
-t, --listList 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/projects

Creates 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 /tmp

Extracts 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.