[unpkg] Uncompact easily on the console

I have to admit that I am ding lazy to unpack on the console. I have never learned 100% what are the parameters or options that must be passed to tar "so that I can unpack a bzip2" or other file, but googling a few days ago I came to this forum and there was a post that I casually took to apply it to it and as a result, make some other modification, always reusing, never reinventing and thanking the one who made the contribution. Thank you, Crunchbang forum.

In the post I said how to create a function in your that would decompress all types of files that it recognized, but that seemed somewhat complicated to me, and especially to the "novice" user, so I decided to make something easier, a script that do the same function, and it is not so difficult to understand, at the end of the story that is what the post is about, or not? xD

First of all, we must know and know which are the compacted files that are most used today. The candidates are ".tar, .bzip, .rar, .zip, .7z and .Z", as well as their combinations in case there are ".tar.bz2, .tar.gz" just to mention a couple of examples.

We must also know how to install them no matter what distribution of GNU / Linux you use. In my case I use Debian it is done as follows:
apt-get install tar bzip2 gzip unrar rar p7zip-full

Now, we already have the ingredients, we just need to mix them in the proper proportion to obtain the xD plate. I called the script unpkg ", it is found or I will leave it in / usr / bin /" and its job is to unzip everything we pass to it as parameters, that is, it can give it 2 or more files and it will unzip them without any kind of problem, something like:

unpkg onion_omelette.rar breakfast_cofee.tar.bz2 cook_recipes.7z

Let's see then the script:
[code] #! / bin / bash
for pkg in $ *; do
if [-f $ pkg]; then
case $ pkg in
* .tar.bz2) tar xvjf $ pkg ;;
* .tar.gz) tar xvzf $ pkg ;;
* .bz2) bunzip2 $ pkg ;;
* .rar) rar x $ pkg ;;
* .gz) gunzip $ pkg ;;
* .tar) tar xvf $ pkg ;;
* .tbz2) tar xvjf $ pkg ;;
* .tgz) tar xvzf $ pkg ;;
* .zip) unzip $ pkg ;;
* .Z) uncompress $ pkg ;;
* .7z) 7z x $ pkg ;;
*) echo "'$ pkg' is a packaged file? Don't know what to do, exiting. » ;;
esac
fi
done
[/ Code]

They realize? There was no need to explain what the file did. So guys, see you in some next post here.


Add as preferred source