Archives

Linux tar command

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

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

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

Examples

List archive contents without extracting.

tar -tf backup.tar.gz

Create a gzip-compressed archive of a project directory.

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

Parameters, options and clauses

Option / clauseDescription
-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.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory