Renaming files in a folder (linux)

Issue

I have a different HTML files in a folder. How to rename the files so that they have the names of:

1.html
2.html
3.html

Solution

This can make it:

i=1
for file in /your/folder/*
do
   mv $file ${i}.html
   i=$((i+1)) #((i++)) was giving errors (see comments)
done

It loops through all files in /your/folder and renames them according to the number $i that keeps increasing.

Answered By – fedorqui

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published