How to use tar to archive and extract files
This article will explain how to use the tar command in Linux to create, list, and extract files.
1. Creating a .tar file
To tar the contents of a single folder: tar -cvf filename.tar /folder1
To tar the contents of a multiple folders: tar -cvf filename.tar /folder1 /folder2 /folder3
To tar multiple files tar -cvf filename.tar file1.txt file2.txt file3.txt
2. Listing the contents of a .tar file (without extracting)
tar -tvf filename.tar
3. Extract the contents of a .tar file
tar -xvf filename.tar
4. Uncompressing a .tgz file
tar -xzvf foo.tgz