What tar is for
tar (tape archive) packs many files and folders into a single file, an archive, keeping their names, folders, permissions and timestamps. It's how Linux software, backups and project releases are shipped around. On its own, tar only bundles; the next lesson adds compression to make the bundle smaller.
Think of it like this: A tar archive is a cardboard box. You put a whole shelf of files in it, tape it shut into one parcel, and later open it to find everything exactly where it was.
The three jobs: c, t, x
tar does one of three things, chosen by the first letter: c create, t list (the table of contents) or x extract. You almost always add f to name the archive file and v (verbose) to see what it's doing. Create an archive of the project folder:
tar -cvf project.tar project
ls -l project.tarIn the terminal
student@vulntech:~$ tar -cvf project.tar project project/ project/src/ project/src/main.py project/src/util.py project/docs/ project/docs/readme.txt project/VERSION student@vulntech:~$ ls -l project.tar -rw-r--r-- 1 student student 10240 Oct 17 15:08 project.tar
-cvf project.tar project reads as create, verbosely, into the file project.tar, the folder project. Now look inside without unpacking:
tar -tvf project.tarIn the terminal (t lists; nothing is unpacked)
student@vulntech:~$ tar -tvf project.tar drwxr-xr-x student/student 0 2026-10-17 15:05 project/ drwxr-xr-x student/student 0 2026-10-17 15:05 project/src/ -rw-r--r-- student/student 12 2026-10-17 15:05 project/src/main.py -rw-r--r-- student/student 7 2026-10-17 15:05 project/src/util.py drwxr-xr-x student/student 0 2026-10-17 15:05 project/docs/ -rw-r--r-- student/student 11 2026-10-17 15:05 project/docs/readme.txt -rw-r--r-- student/student 5 2026-10-17 15:05 project/VERSION
Extracting
-x unpacks. Do it somewhere empty so you can see what comes out:
mkdir restore
cd restore
tar -xvf ../project.tar
ls
ls project/srcIn the terminal
student@vulntech:~$ mkdir restore student@vulntech:~$ cd restore student@vulntech:~/restore$ tar -xvf ../project.tar project/ project/src/ project/src/main.py project/src/util.py project/docs/ project/docs/readme.txt project/VERSION student@vulntech:~/restore$ ls project student@vulntech:~/restore$ ls project/src main.py util.py
Common mistake: An archive usually contains a top folder (
project/), so extract it in an empty directory. Unpacking in a folder full of work can scatter files everywhere and overwrite them. Alwaystar -tf archive.tarfirst to see what's inside.
Tip:
tar -xf archive.tar -C /path/to/dirextracts straight into another folder, withoutcd-ing there first. Make the folder withmkdirbeforehand.
Remember:
tar -cf out.tar stuffcreates,tar -tf out.tarlists,tar -xf out.tarextracts. Addvto watch,falways names the file.