Tuesday, April 7, 2009

Recursively rename files

I knew the command for finding files in recursive fashion + I knew command for renaming the files = I now know how to recursively rename the files

find . -type f -name *.txt -exec rename -v 's/.txt/.xml/' {} \;

Similarly, say for example if you need to recursively delete the (.exe) files from your USB stick, you may use following command:
find /path/to/usb/dir -name '*.exe' -print -exec rm -f {} \;

and to remove files below size 200 use command:
find . -type f -size -200 -exec rm {} \;
or somthing like
find . -name '*.exe' -exec rm {} \;

Hope this is helpful to other people too.

1 comment:

Ameya Aloni said...

Wondering whether similar commands are present for Windows too ????

If found, I will add here soon .... till then it is all yours ....