Linux Command - tar

tar - Archiving utility. Often combined with a compression method, such as gzip or bzip.

Syntax

1
tar [OPTION...] [FILE]...
Option Description
-c create a new archive
-f specify archive file
-t list
-x extract
–exclude exclude files, given as a pattern
Compression Option Description
-z use gzip
-j use bzip2
-Z use compress

Example

Create archive from files

1
tar -cvf archive.tar file1 file2 dir1 dir2

Create gzipped archive

1
tar -czvf archive.tar.gz file1 file2 dir1 dir2

List files in archive

1
tar -tvf archive.tar

List files in gzipped archive

1
tar -tzvf archive.tar.gz

Extract files from archive

1
tar -xvf archive.tar

Extract files from gzipped archive

1
tar -xzvf archive.tar.gz

Extract an archive in a target folder

1
tar -xvf archive.tar -C dest

Extract specific files an archive

1
tar -xvf archive.tar file1

Reference