Wednesday, July 30, 2014

Unix/Linux tar command

What is it? Why do we need it? Remember in windows how you have .zip files. Why do we use them? The first thing to remember is that computers usually store data in files. Data files, Image files, Java files, Text files......files galore.

Now say we had 5 files in different locations or in the same location. And we wanted to gather these 5 files and treat them as 1 file. Why would we want to do this? Is it easier to transport or move 1 file or 5 distinct files?

Another benefit is compression. When you go on a trip, you have to pack your suitcase. In order to make more space you push your clothes down, packing them as tightly as possible. Similarly, to save space you can compress data.

The 2 basic things we want to accomplish is either zip/compress or unzip/decompress. Just like a tire. You either fill air an inflate or release air and deflate.We can do this using the tar command in unix/linux:

The command tar, with the -cf option: tar -cf  filename   directory_path

What this does is simply creates a .tar file, which is like the .zip file in Windows. These are conceptually known as archive files.

Say you had an archive file with the .tar extension and you wanted to unzip it. Which is basically do the opposite. How would you do it?

Use the tar command, with the -xf option: tar -xf filename  -C directory_path

You may be wondering what the letter c (lowercase) and x (lowercase) stands for. The letter c when used as an option with the tar command stands for create. Makes sense right? Because we are creating an archive file. The letter x when used as an option with the tar command stands for extract. Makes sense too right? Because we are trying to extract files from the archive file. Well what's the capital C in the tar -x command for? That specifies the directory.

To read/learn more check out the following link: