Unzip, untar, unpack all archives

September 15, 2007 – 21:13

Once I came to a point of having downloaded 20+ tar.gz files and facing a need of finding an efficient way to extract them. If you are having such a problem then this simple solution will help:

for F in `find ./ -type f -name '*tar.gz' -print`;
do tar xvzf $F;
done;

What it does is for every file ending with “tar.gz” found in current folder “./” it executes a command “tar xvzf“, which unpacks the archive. Very simple but also VERY useful. Try with unzip and other commands.
Yes, you may delete files after unpacking by adding “rm $F;” after the tar statement.
However, it is always good to keep the original source!

Post a Comment