tar
The tar (tape archive) command is used to combine multiple files and directories into a single archive file, often called a tarball. It can also integrate with compression tools like gzip and bzip2 to compress the archive.
Basic Syntax
tar [OPTION...] [FILE]...
Common Options
| Option | Description |
|---|---|
-c, --create | Create a new archive. |
-x, --extract | Extract files from an archive. |
-t, --list | List the contents of an archive. |
-v, --verbose | Verbosely list files processed. |
-f, --file=ARCHIVE | Use archive file or device ARCHIVE. |
-z, --gzip | Filter the archive through gzip. |
-j, --bzip2 | Filter the archive through bzip2. |
-J, --xz | Filter the archive through xz. |
Real-world Examples
-
Create an uncompressed archive of a directory:
tar -cvf backup.tar /path/to/directory -
Create a gzip-compressed archive:
tar -czvf backup.tar.gz /path/to/directory -
Extract a gzip-compressed archive:
tar -xzvf archive.tar.gz -
List contents of an archive without extracting:
tar -tzvf archive.tar.gz