Find files in sub-directories and unpack them in place

I have a lot of zip and rar archives in various sub-directories, which I wanted to extract but to leave the files in their sub-directories.

I have used for a long time this command to search for files and extract them in working directory:

find ./ -iname "*.zip" -print0 | xargs -0 -I {} 7z -y x {}

Which works OK if you want your files all to be extracted to the directory where you started the find command. But to leave files in their own folder this command was not appropriate.

It seems that find command has this neat flag called “-execdir” which does exacty that what I wanted, so here are few examples:

Find all zip files in sub-directories and unzip them in place using unzip:

find ./ -iname "*.zip" -execdir unzip -o '{}' ';'

Find all rar files in subdirectories and unzip them in place using unrar:

find ./ -iname "*.rar" -execdir unrar e '{}' ';'

The same using 7zip would look like:

find ./ -iname "*.zip" -execdir 7z -y x '{}' ';'

and

find ./ -iname "*.rar" -execdir 7z -y x '{}' ';'

Later on if you want to delete your zip and rar files and only leave the contents you can use similar command from where I have started.

For example to delete all rar archives that are named .rar, r00, r01 … r0x you can use:

find ./ -iname "*.r??" -print0 | xargs -0 -I {} rm {}

and similar you can can use to delete zip files, but please make sure that you don’t have zip files in your zip archives that you do not want to delete:

find ./ -iname "*.zip" -print0 | xargs -0 -I {} rm {}

Multiple file rename using regular expression

I have a bunch of episode files in my directory that I would like to rename to proper S[XX]E[YY] format.

Current directory listing looks like this:

S1 Episode 10.avi S1 Episode 11.avi S1 Episode 12.avi S1 Episode 13.avi S1 Episode 14.avi S1 Episode 15.avi S1 Episode 16.avi S1 Episode 17.avi S1 Episode 18.avi S1 Episode 19.avi S1 Episode 1.avi S1 Episode 20.avi S1 Episode 21.avi S1 Episode 22.avi S1 Episode 23.avi S1 Episode 24.avi S1 Episode 25.avi S1 Episode 26.avi S1 Episode 27.avi S1 Episode 28.avi S1 Episode 2.avi S1 Episode 3.avi S1 Episode 4.avi S1 Episode 5.avi S1 Episode 6.avi S1 Episode 7.avi S1 Episode 8.avi S1 Episode 9.avi S2 Episode 10.avi S2 Episode 11.avi S2 Episode 12.avi S2 Episode 13.avi S2 Episode 14.avi S2 Episode 15.avi S2 Episode 16.avi S2 Episode 17.avi S2 Episode 18.avi S2 Episode 19.avi S2 Episode 1.avi S2 Episode 20.avi S2 Episode 21.avi S2 Episode 22.avi S2 Episode 23.avi S2 Episode 24.avi S2 Episode 2.avi S2 Episode 3.avi S2 Episode 4.avi S2 Episode 5.avi S2 Episode 6.avi S2 Episode 7.avi S2 Episode 8.avi S2 Episode 9.avi S3 Episode 10.avi S3 Episode 11.avi S3 Episode 12.avi S3 Episode 13.avi S3 Episode 14.avi S3 Episode 15.avi S3 Episode 16.avi S3 Episode 17.avi S3 Episode 18.avi S3 Episode 19.avi S3 Episode 1.avi S3 Episode 20.avi S3 Episode 21.avi S3 Episode 22.avi S3 Episode 23.avi S3 Episode 24.avi S3 Episode 2.avi S3 Episode 3.avi S3 Episode 4.avi S3 Episode 4.avi S3 Episode 6.avi S3 Episode 7.avi S3 Episode 8.avi S3 Episode 9.avi

Continue reading “Multiple file rename using regular expression”

ntfsclone Windows partition to smaller partition on another disk

First of all you will need some kind of bootable Linux distribution. I have used Kali linux. Please execute following commands as root.

First check which partition do you use for your Windows installation. Since I was using Windows 7, first partition was 100MB reserved space and second partition was my Windows installation. Continue reading “ntfsclone Windows partition to smaller partition on another disk”