Archives with tar
Packing many files into one.
To send a whole folder to someone, or back it up, it's much easier to pack it into a single file first. On Linux, the classic tool for that is tar.

- Send or back up a folder
- Pack it into one file
- tar
Creating an archive
Tar dash CVF means create, verbose, and file. Create a new archive, list each file as it's added, and write it to the file name that comes next. Here we pack the whole Documents folder into documents dot tar. LS dash L shows the new archive.
tar -cvf documents.tar Documents Documents/ Documents/cv.txt Documents/report.txt ls -l documents.tar -rw-r--r-- 1 sam sam 10240 Jan 5 09:00 documents.tar
Looking inside, and unpacking
Tar dash TF lists what's inside, without unpacking. And dash XF extracts it. Here we make a new folder, restore, go into it, and extract the archive there. The Documents folder appears, with both files.
tar -tf documents.tar Documents/ Documents/cv.txt Documents/report.txt mkdir restore && cd restore tar -xf ../documents.tar ls Documents cv.txt report.txt
Remembering the letters
Tar's letters look scary, but there are only a few to remember. C to create, X to extract, T to list. F for the file name, which must come last in the group. And V for verbose, if you want to see each file. Remember, create, extract, table of contents.
| Letter | Means |
|---|---|
| c | create an archive |
| x | extract |
| t | list the contents |
| f | the archive file name |
| v | verbose: show each file |
Summary
Tar dash CF creates an archive, dash TF lists it, and dash XF extracts it. Next, making archives smaller, with compression.
Key takeaways- tar -cf a.tar folder
- tar -tf a.tar
- tar -xf a.tar