tar Command Cheat Sheet

2022-03-14

tar command archives files/directories, or extracts the archives.
In this article, I listed examples which we would use often.

For zipand gzip and bzip2, please check the post.


Create archive from a file

1
tar -cf archive.tar sample.txt

If you want to display the result,

1
tar -cvf archive.tar sample.txt

Create archive from multiple files

1
tar -cf archive.tar sample1.txt sample2.txt

Append new files to the archive

1
tar -rf archive.tar sample.txt

Delete files from the archive

1
tar --delete -f archive.tar sample.txt

Extract archives

1
tar -xf archive.tar

If you want to display the result,

1
tar -xvf archive.tar

View the contents of the archive

1
tar -tf archive.tar