All About Tar Files And How To tar, untar Files In Linux Using Terminal
tar is an archive utility tool for GNU/Linux. Primarily used to distribute executable software or package the software source code in the tarball for later distribution. The most popular being gzip and you might have noticed the source file of a program usually ends with *.tar.gz. Well, that doesn’t mean you can’t use it to create an archive for other file types. You can.
Archive a file
Well, let’s learn how to archive a file. Launch terminal using ctrl+alt+t and cd into your Music directory, choose a song you wish to archive.
In my case, I’ve chosen the song Kevin_S._-_Universum.ogg.
Now let’s tar it!Type in –
tar -cf universum.tar Kevin_S._-_Universum.ogg
Hit Enter and you’ll see the audio file has been archived.
Some more commands
tar is the program for manipulating a tarball and the arguments:
-c tells tar to create a new archive
-f specifies the file for the tar program
-f specifies the file for the tar program
Then again tar supports combination of arguments so you don’t have to explicitly pass arguments as in –
tar -c -f output.tar input.file
The third argument universum.tar is the output of the program and the fourth following it is the input file.
So, overall we have this format.tar arguments <output file> <input file(s)>
So, overall we have this format.tar arguments <output file> <input file(s)>
Untar Files
Well someone sent you a *.tar file and you wish to extract the contents. So onto the previous file, we just created, here is the CLI way to untar it.
tar -xf universum.tar
But before I hit Enter I must make sure the audio file is deleted to avoid overwriting.
then…
hit Enter and the file is extracted.
How to tar multiple files?
What if you wanted to tar multiple audio files at once? This is best done by specifying multiple arguments like the one below shows how to tar two audio files at once.
tar -cf audio.tar song1.ogg song2.ogg
But what if you wanted to tar all the audio files at one go? Here is how it is done –
tar -cf audio.tar *.ogg
Let’s nerd
Now, for instance, you archived the file but you want to make sure it really is in the file. Don’t worry here is the solution to view the list of file(s) in the *.tar file –
tar -tf audio.tar
Need more detailed information or you might want some output as tar carries out its work. This is done by enabling verbosity.
tar -cf audio.tar *.ogg -v
or
tar -xf audio.tar -v
or
tar -xf audio.tar -v
Remember you cannot pass verbosity along with the arguments of the tar program in conjunction! This is because -1. tar don’t do it that way.
2. verbosity exists almost in every Linux utility program
2. verbosity exists almost in every Linux utility program
Conclusion
That’s about it for now. You have just learned one of the basic stuff every FOSS developers out there do. Maybe it’s not sufficient enough for the programmers out there but the basic is outlined and you may further go on how to package your source code in *.tar.gz (Easy-bitsy just a few arguments to pass).