Recursicely search and rename file extension

Greetings to all!!:b:

I have one root folder containing several other folders inside it. This tree structure is deep. And the files are of similar extension.

I need to start at the top level and recursively search and rename all the files with say .a extension to .b .

This is the code to rename, but then I need to reach out each folder.
for i in *.vw ; do mv $i `echo $i | sed 's/vw/view/'` ; done

Could anybody help me by providing the outer for loop to traverse all the folders in between?

man find or search these forums for examples; there are plenty.

You can avoid the sed call, there's a simple substitution operator built into the shell itself.

mv "$i" "${i%.wv}.view"

Also note the use of double quotes.

In relation to Search for all the unique file extension just pipe the output of find to sed and trim away everything except the extension.

Find utility will go recursively down the line ...

for i in `find . -name "*.vw"`
 do
      mv "$i" "${i%.vw}.view"
 done

except that this method is prone to error with spaces in file names. use while loop instead

find . -name "*.mp3" | while read line; 
  do 
        mv "$line" .......
 done

Hi,

Below can list out all the different extension names in the current directory.
Hope it can help you a little.

getDel()
{
	cd $1
	for i in *
	do
		if [ $i != "*" ]
		then
			if [ -d $i ]
			then
				getDel $i
			else
				ls -l $i
			fi
		fi
	done
	cd ..
}

for i in *
do
if [ -d $i ]
then
	getDel $i
else
	ls -l $i
fi
done  > temp

awk '{
if (index($9,".")!=0)
{
	t=substr($9,index($9,".")+1,length($9)-index($9,"."))
	a[t]=1
}
}
END{
for ( i in a)
print i
}' temp
rm temp

Isn't that a bit excessive, code-wise?

find . -type f | sed -e 's/.*\.//' | sort | uniq -c | sort -rn

:slight_smile:

Thanks to everyone....
I got the solution and customized it according to my reuirement.

Wish you all the best!!:b: