Wednesday, 2 February 2011

Howto: Unpack/Extract Files from Multiple Folders in One Go

Just recently I had a situation where I needed to extract multiple archives, roughly 100 in fact, with each being in a sub folder.

Not particularly wanting to sit clicking into each folder, right click the archive and extract each one, then move the file (avi in this case) up into the parent folder I got busy on the terminal. Luckily this is a perfect job for Bash and instead of the job taking around 2hrs of tedious clicking and waiting to extract each I was able to leave the command processing the files and get on with some more interesting work while the job was done.

So here is the command line that go it all sorted.

  cur="`pwd`";for i in `"ls"`; do echo "$i";cd "$i";unrar e "*.rar";mv "*.avi" "$cur"/ ;cd "$cur";done

So its not very elegant, I was going to use "find" but as I wanted to move the avi at the same time, thought this way would be better.

I would be happy for anyone to leave a comment and show me a better way, always eager to learn :]