Everything about Tar

.tar ,.tar.gz ,.tar.bz2 . Do you know the difference between all of those extensions?

Tar is an archive file which means it is a container for many files. Tar is used to collect many files as a single file.
gz is an abbreviation for Gzip, it is a lossless compression algorithm used to compress a file.
bz2 is an abbreviation for Bzip2, it is also a lossless compression algorithm. The main difference between gzip & bzip2 is the algorithm itself. Gzip can compress a file faster but the size of the compressed file is bigger than Bzip2.

So .tar extensions mean it is an archived file, whether .tar.bz2 & .tar.gz means it is a compressed archive file.

Tar Terminal Command

tar command on the terminal has many flags, it intimidated me when I first learn about it. I want to share some of the information regarding the most used flag.

tar flag cheatsheets

Those flags can be combined when creating a command on the terminal.

archiving file

c indicating that we are going to create a tar file from the specified path, fmeans give the archived filename ofarchivedFileName.tar . v indicating verbose, it will print out the process on the terminal when archiving process going on.

create a compressed archived file

use z when using Gzip algorithm, use j when using Bzip2 algorithm.

x indicate that you are going to untar the files. you can use the same command for both archived and compressed archived files. f in this case, indicates what file you are going to untar. -C indicates the path you want your files to be collected after untar process is done. By default untar process will collect your data in the current directory.

list the data inside archived files

t indicates that you are going to see the data inside the archived files. tvf inspect the data recursively, which means if there is a folder inside the archived file, it will inspect all the data inside of it. ls -l inspect the data inside the archived file only. It won’t look recursively inside the folder (if there are any).

unarchiving certain file

you can also extract only certain files (not all of them). The flags are slightly different based on the type of extension.

unarchiving multiple files

You can also unarchive multiple files using double-quote syntax.

unarchiving group of data using wildcard

you can also extract data with certain pattern names using --wildcard flags.

appending data inside archived file

You can also add data inside the archived files using r flag. One thing to remember here is that we CAN NOT add data to the compressed archived file. So make sure that you use r flag only on .tar files.

Split Feature

There is another feature that works well with the tar command. It is Split command. It helped us split big data into small pieces chunks. It helps when we are going to send the data over the internet.

splitting example

Assume we want to send the data inside /app/data . Supposed that the data is too big so we want to divide it into some pieces of small chunks. So after we compressed the archived file using Bzip2 algorithm. We split it by 10 Megabytes using split -b 10M command. Data that has been separated will be named archivedFile.tar.bz2.part** , you can specify the pattern that you wish using double-quote syntax in the last command.

combined command for archiving and spliting
combining chunk files into one file

You can merge all chunks files before into one file using cat command. Using split data can help a lot when sending data over the internet, especially when the bandwidth is slow.


If you find this article helpful, and you want to support me to upload more content like that, you can buy me a coffee by clicking here.




Software Engineer | Deep Learning Enthusiast | writer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Setup SFTP Server Ubuntu

| Engineering News-Record

From Zero to Service — A Guide on Creating an API using Java Spring Boot

7 Conversational Habits That Reveal Someone’s True Character

My First Two Weeks as Director of Technology at a Startup

Colouring graphs for a wireframe shader

Why Developers Are Leaving VMs

| Engineering News-Record

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yosua Hanjaya

Yosua Hanjaya

Software Engineer | Deep Learning Enthusiast | writer

More from Medium

Command Shortcuts — Simple Productivity booster for Linux

Process management, scheduling, and communication in Linux

Message queues

Loading order of .bash_profile or .bashrc: Unix & macOS

Deepin 20.5 — Agile Development of Mail