Renaming all files

Hi,

Very silly question. I need to rename all my files located in one particular folder. The names are Results1.dis, Results2.dis, Results3.dis, etc. I need to change the names to Results001.dis, Results002.dis, Results003 so on and so forth. Now, Files with double digits such as Results17.dis should be renamed Results017.dis. Files with triple digits should be kept the same (Results159.dis).
Any help will be greatly appreciated.

perl -e'
	($n = $_) =~ s/(\d+)/sprintf "%03d", $1/e and
	rename $_, $n
	  for glob "*.dis"
  ' 

Thank you very much!

for i in `ls *.dis`
do 
   mv $i Results$(printf "%03d\n" $(echo "$i" | grep -o "[0-9]*")).dis
done

@Xterra, please add "echo" to the statement in order to be safe running. Once you're satisfied then remove the echo.

Please let me know any fine tuning here to make it more simple :slight_smile: