How to create/add to/extract tar and tar.gz files

Create a tar file:

tar -cvf archive.tar file1.txt file2.txt file3.txt

Create a tar.gz file (compressed tar file):

tar -cvzf archive.tar.gz file1.txt file2.txt file3.txt

Compress a tar file:

gzip archive.tar

Add files to a tar file (doesn’t work for .gz):

tar -uvf archive.tar file4.txt file5.txt file6.txt

Extract tar or tar.gz file:

tar xvf archive.tar.gz