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.
Examples:
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!
Related articles
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Please click on the following link to open the newsletter signup page: Ghacks Newsletter Sign up
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.
This should be called working with archives in bash, because when I do stuff with archives I use engrampa. I guess some people prefer to do everything in the command line but for archive management I prefer a gui.Thank you though for showing me.
Love these back to basics Linux tutorials. Please keep them coming.
Most Linux distros also come with GUI Archive Manager.
Great