Linux tar Command – Creating tar file via CLI

Creating a tar archive

tar -cvf archiveName.tar directoryToPack/


tar -cvf archiveName.tar /dir1 /dir2 file1 file2


tar -cvf archive.tar /dir/music /dir/photos /dir/text.txt

Unpacking tar

tar -zxvf archiveName.tar

You can also unpack single files or directories using their list (divided by spaces) at the end of the command:

tar -xf archiveName.tar file1 file2 dir1 dir2

Packaging the same file formats

tar cvzf allphps.tar *.php

List the contents of a tar file
List all files in allphps.tar

tar tvf allphps.tar

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.