Tar

Tape archive is a file format used to archive folders.

Command usage

tar <option> <file>

Operations

Append

-r or --append

tar -rvf archive.tar file.txt

Create

-c or --create

tar -cvf archive.tar file.txt

Extract

-x or --extract or --get

tar -xvf archive.tar

List

-t or --list

tar -tvf archive.tar

Update

-u or --update

tar -uvf archive.tar file.txt

Options

Compression

Tar can be used with compression tools like gzip or bzip2.

Gzip

-z or --gzip

tar -czf archive.tar.gz file.txt
Bzip2

-j or --bzip2

tar -cjf archive.tar.bz2 file.txt
XZ

-J or --xz

tar -cJf archive.tar.xz file.txt

File

-f or --file

tar -cf archive.tar file.txt

Verbose

-v or --verbose

tar -cvf archive.tar file.txt

Directory

-C or --directory

tar -cvf archive.tar -C /path/to/directory .

Wildcard

tar -cvf archive.tar *.txt

Exclude

--exclude

tar -cvf archive.tar --exclude='*.txt' .