Renaming files

Sigma721

Well-Known Member
Joined
Sep 14, 2011
Messages
122
Reaction score
0
Hi everyone

I am new to linux and have a question which Google has not been able to answer.

I have a folder with a few files in:
index.html
index1.html
index2.html
Etc

The number of files will vary. The issue I have is that I want to rename index.html to index1.html after renaming index1.html to index2.html, etc and take the highest numbered file "indexX.html" and rename it to index.html.

Anyone have any ideas?

Im running Raspbian.

Thanks for any help in advance
 
This is quick and dirty, and come with no guarantees of any sort (so make a backup for your stuff first).

How many files are index?.html (excluding index.html)? In my example, I have index.html, index1.html trough index15.html.

Replace the 15 with whatever you have:

Code:
for i in $(seq 15 1) ; do a=$(($i + 1)) ; mv -v index$i.html index$a.html ; done

Once that's done, just rename the index.html file manually

Code:
mv -v index.html index1.html

Why do I do the for loop backwards? Because it will eat your files if you don't...
 
Top
Sign up to the MyBroadband newsletter
X