Think of tar as a cardboard box. You put your folders and files inside it to keep them together, but the box itself doesn't make the items smaller.
A .tar file is roughly the same size as the sum of all the files inside it.
If you delete the .tar file, the original files won't be affected
To actually reduce the file size, you need a compressor like gzip, bzip2, or xz.
This gives you the double extensions you see in the tutorial, such as .tar.gz or .tar.xz.
tar [Flags] [Directory to save]/[Archive Name].[Archive File Format]
Example: tar -cvf /root/my_archive.tar
-c Tells tar to create a new archive.
-v Displays the progress in the terminal, showing you exactly which files are being processed.
-t Lists the contents of an archive without extracting it.
-x Unpacks the files from the archive back into the system.
-f Specifies the name of the archive file. This must always be the last flag before the filename.
Table 13.1 Compressor flag
Create several files for demonstrations purpose
history > log_1.txt
history > log_2.txt
Archiving two files
tar -cvf arc_log.tar log_1.txt log_2.txt
Display archived file content without extract
tar -tvf arc_log.tar
Compress two files by using gzip
tar -cvzf arc_log.tgz log_1.txt log_2.txt
Display compressed file content without extract
tar -tvf arc_log.tgz
Verify size of original files, archived file and compressed file
Archived file size should be more than sum of original files size.
Compressed file size should be less than archived file size.
ls -l
Delete the original files
rm -rf {log_1.txt,log_2.txt}
ls
Extract the archived file
tar -xvf arc_log.tar
Verify extracted content from archived file
ls -1
Delete the extracted content from archived file
rm -rf {log_1.txt,log_2.txt}
ls
Extract the compressed file
tar -xvf arc_log.tgz
Verify extracted content from compressed file
ls -l
Result
student@localhost:~$ history > log_1.txt
student@localhost:~$ history > log_2.txt
student@localhost:~$ tar -cvf arc_log.tar log_1.txt log_2.txt
log_1.txt
log_2.txt
student@localhost:~$ tar -tvf arc_log.tar
-rw-r--r-- student/student 12540 2026-04-08 11:22 log_1.txt
-rw-r--r-- student/student 12567 2026-04-08 11:22 log_2.txt
student@localhost:~$ tar -cvzf arc_log.tgz log_1.txt log_2.txt
log_1.txt
log_2.txt
student@localhost:~$ tar -tvf arc_log.tgz
-rw-r--r-- student/student 12540 2026-04-08 11:22 log_1.txt
-rw-r--r-- student/student 12567 2026-04-08 11:22 log_2.txt
student@localhost:~$ ls -l
total 68
-rw-r--r--. 1 student student 30720 Apr 8 11:22 arc_log.tar
-rw-r--r--. 1 student student 3695 Apr 8 11:23 arc_log.tgz
drwxr-xr-x. 2 student student 6 Feb 12 09:48 Desktop
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Documents
drwxr-xr-x. 2 student student 6 Feb 27 11:58 Downloads
-rw-r--r--. 1 student student 12540 Apr 8 11:22 log_1.txt
-rw-r--r--. 1 student student 12567 Apr 8 11:22 log_2.txt
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Music
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Pictures
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Public
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Templates
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Videos
student@localhost:~$ rm -rf {log_1.txt,log_2.txt}
student@localhost:~$ ls
arc_log.tar arc_log.tgz Desktop Documents Downloads Music Pictures Public Templates Videos
student@localhost:~$ tar -xvf arc_log.tar
log_1.txt
log_2.txt
student@localhost:~$ ls -l
total 68
-rw-r--r--. 1 student student 30720 Apr 8 11:22 arc_log.tar
-rw-r--r--. 1 student student 3695 Apr 8 11:23 arc_log.tgz
drwxr-xr-x. 2 student student 6 Feb 12 09:48 Desktop
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Documents
drwxr-xr-x. 2 student student 6 Feb 27 11:58 Downloads
-rw-r--r--. 1 student student 12540 Apr 8 11:22 log_1.txt
-rw-r--r--. 1 student student 12567 Apr 8 11:22 log_2.txt
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Music
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Pictures
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Public
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Templates
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Videos
student@localhost:~$ rm -rf {log_1.txt,log_2.txt}
student@localhost:~$ ls
arc_log.tar arc_log.tgz Desktop Documents Downloads Music Pictures Public Templates Videos
student@localhost:~$ tar -xvf arc_log.tgz
log_1.txt
log_2.txt
student@localhost:~$ ls -l
total 68
-rw-r--r--. 1 student student 30720 Apr 8 11:22 arc_log.tar
-rw-r--r--. 1 student student 3695 Apr 8 11:23 arc_log.tgz
drwxr-xr-x. 2 student student 6 Feb 12 09:48 Desktop
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Documents
drwxr-xr-x. 2 student student 6 Feb 27 11:58 Downloads
-rw-r--r--. 1 student student 12540 Apr 8 11:22 log_1.txt
-rw-r--r--. 1 student student 12567 Apr 8 11:22 log_2.txt
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Music
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Pictures
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Public
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Templates
drwxr-xr-x. 2 student student 6 Jan 13 16:55 Videos