Forever & AlwaysLINUX COMMAND ATLAS

LINUX COMMAND ATLAS · COMMAND GUIDE

Linux tar command

Create or inspect tar archives. This example lists files without extracting them.

GNU Tar

Syntax

Command form
tar MODE [OPTION]... ARCHIVE [FILE]...

Common options

8 options
OptionWhat it does
-c, --createCreate a new archive.
-x, --extractExtract files from an archive.
-t, --listList archive contents without extracting.
-f, --file=ARCHIVEUse the specified archive file.
-z, --gzipFilter the archive through gzip.
-J, --xzFilter the archive through xz.
-C DIRChange to DIR before processing files.
-v, --verboseList processed files.

Usage examples

2 examples

Create or inspect tar archives. This example lists files without extracting them.

tar -tf backup.tar.gz

Create a gzip-compressed archive of a project directory.

tar -czf site-backup.tar.gz -C ./project .

Notes

Inspect untrusted archives before extraction. Options and compression autodetection can vary; archive paths may contain absolute or parent-directory entries.