tar

Tape ARchive. Used to collect many files into one archive file, often compressed significantly.

Synopsis

tar [options] [archive-file] [file or directory to be archived]

Core Options

-c

Create a new archive.

-x

Extract files from an archive.

-z

Filter the archive through gzip (for .tar.gz).

-v

Verbose. List files processed.

-f file

Use archive file or device ARCHIVE.

-t

List the contents of an archive.

Usage Examples

Create Compressed Archive

Create a gzip-compressed tarball of the 'project' directory.

tar -czvf project.tar.gz project/

Extract Archive

Extract a .tar.gz file to the current directory.

tar -xzvf archive.tar.gz

List Contents

List files inside the archive without extracting them.

tar -tf archive.tar.gz

Extract to Specific Directory

Extract files to the /tmp folder.

tar -xzvf archive.tar.gz -C /tmp

Create Archive Excluding Files

Create archive but exclude 'node_modules'.

tar --exclude='node_modules' -czvf project.tar.gz project/
Built for builders.