Greetings to all!!
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?
era
April 9, 2008, 4:26pm
2
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.
era
April 9, 2008, 5:25pm
3
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.
rubin
April 9, 2008, 8:41pm
4
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
era
April 10, 2008, 2:29am
7
Isn't that a bit excessive, code-wise?
find . -type f | sed -e 's/.*\.//' | sort | uniq -c | sort -rn
Thanks to everyone....
I got the solution and customized it according to my reuirement.
Wish you all the best!!