Operating System - HP-UX
1833868 Members
2004 Online
110063 Solutions
New Discussion

Re: How to rename 10000 files

 
SOLVED
Go to solution
praveen..
Super Advisor

How to rename 10000 files

Hi,
I have 10000 file named *.htm in one directory.
and I need to rename these files from *.htm to *.html

How can i remane all these files?

Please suggest
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: How to rename 10000 files

Something like this from the # should work:

cd /dir
for FILE in *.htm
do
mv ${FILE} ${FILE}l
done
Xavier Gutierrez_2
Frequent Advisor

Re: How to rename 10000 files

Hi,

My way:

ls *.htm | awk -F "." '{print $1}' | while read vFile
do
mv $vFile.htm $vFile.html
done

Cheers,

XG.-
A. Clay Stephenson
Acclaimed Contributor

Re: How to rename 10000 files

Something like this should get you started:

ls *.htm | while read X
do
NEWNAME=${X}l
if [[ ! -f ${NEWNAME} ]]
then
mv ${X} ${NEWNAME}
else
echo "${NEWNAME} already exists." >&2
fi
done


Because you have some many *.htm files in one directory, you may need to change the ls *.htm to something like ls [a-g]*.htm and do only a portion of themn at a time.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: How to rename 10000 files

Hi Praveen:

Yet another way:

# ls *.htm | xargs -i mv {} {}l

Regards!

...JRF...
praveen..
Super Advisor

Re: How to rename 10000 files

Thanks, All are working

Thanks