man.lsPlain-English help for Unix commands

tar Bundle and unbundle files into archives

Packs many files and folders into one archive file, and unpacks them again. Add compression and you get the familiar .tar.gz or .tgz file. You use it for backups, for sending a folder as one file, and for unpacking downloads.

Synopsis

tar -c [-z] -f archive [files ...]
tar -x [-z] -f archive [-C directory]
tar -t [-z] -f archive

Common options

Option or formWhat it does
-cCreate a new archive from the files and folders you name
-xExtract files from an archive
-tList the contents of an archive without extracting anything
-f archiveThe archive file to write or read. It must come right before the file name, so write -czf backup.tgz, not -cfz backup.tgz
-vVerbose: print each file as it is processed
-zCompress with gzip when creating, or decompress gzip when reading. Use it for .tar.gz and .tgz files
-C directoryChange to this directory first. When extracting, files go there instead of the current folder
--exclude patternSkip files and folders whose names match the pattern. Quote the pattern so the shell does not expand it

Examples

List what is inside an archive
tar -czf backup.tgz docs && tar -tzf backup.tgz
Create a compressed archive of a folder
tar -czf backup.tgz docs
Unpack into a new, empty folder
tar -czf backup.tgz docs && mkdir restore && tar -xzf backup.tgz -C restore && ls restore
docs
Extract without naming the compression
tar -czf photos.tgz photos && mkdir out && tar -xf photos.tgz -C out && ls out/photos
a.jpg
b.jpg
Leave some files out of the archive
tar --exclude='*.jpg' -czf site.tgz docs photos && tar -tzf site.tgz
Archive a folder from another location, without its full path
tar -czf html.tgz -C /var/www html

Notes

See also

Last reviewed 2026-10-07.