Say, for e.g. you have a lot of files that are scattered across different folders that you would like to rename from .txt to .doc

In order to get that done:

  • Find the .txt files
  • rename each .txt file to .doc

The Script

for i in `find /home/Documents -name *.txt`; do v=`ls $i|sed s/.txt/.doc/`; mv $i $v; done

Note: Replace /home/Documents with the folder name where you want to recursively search
Replace *.txt/.txt with the required file extension for the search
Replace .doc with the file extension the files should be renamed to