So, last time we learned to use the grep command to search through documents, searches, processes, etc, but what about working with archives? What good is working from the commmand line, if you get stuck the moment you have to unpackage something?
Thankfully, I actually find it incredibly simple to extract and package things via terminal in comparison to using something like Ark.
It’s come to the point where I’ll tend to extract things via terminal, after downloading them from Firefox, rather than clicking through Firefox / my archive manager for two minutes, when I can extract it in about 10 seconds myself.
Zip files have got to be the easiest thing to work with, in the world... In my opinion. Let’s assume that for the duration of these examples, we want to work with packages called example1.zip example2.zip etc.
Another very popular archive type in the GNU/Linux world, are tarballs, however they can be a little more confusing at first to new users.
Tarballs generally come in three flavours:
Working with these files is all basically the same for the three, with just minor differences of a change in options used with your command.
Extracting: tar -xf example1.tar
Compressing: tar -cf example1.tar a.txt
This will create .tar, putting the a.txt file inside the archive. You can follow the same concept as with others, adding multiple file names, or by using the * wildcard, to add multiple files, or specify the directory you wish compressed instead.
When working with .tar.gz or .bz2 archives, you must add a different option depending on whether you wish to use gzip (generally faster, but larger filesizes) or bzip2 (generally slower, but more compressed). You may access the tar manual on the Gnu website.
The options: c=create, f=file, x=extract, r=append, W=verify
Lastly, if you want a more verbose (detailed) output for all of the above, add v to the end of your options before f:
Archives are incredibly easy to handle, and with time and patience your fingers will fire off on their own over time and work magic before your eyes with little effort. Happy hacking!
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.