1

I have been looking an older question answering a similar question, but apparently I am not too good at making the code work. I am on zsh not bash, but other bash shell scripts have worked fine, so I think that it is okay.

I have tried from prompt (inline)

$i=107;for i in *.jpg;do mv "$i" "$i.jpg" $i=$((i+1)); done

basically, I want the current name to become as follows:

107.jpg 108.jpg 109.jpg 110.jpg

etc to the end of the list.

Hope someone can help me with the code, was wanting to use seq I think?

Thnaks,

2 Answers2

1

You want to use two separate variables for the index being incremented and the file name being processed:

i=107; for file in *.jpg; do mv "$file" "$((i++))".jpg; done
Snake
  • 1,650
0

Since you are using zsh, you could avoid the explicit loop by using its zmv module:

autoload zmv

i=107; zmv -n '*.jpg' '$[i++].jpg'

Remove the -n once you are happy with the proposed operations.

steeldriver
  • 81,074