1

I have a lot of files to process and I need to replace their original names with this format in bash:

00000000000001_1.jpg 
00000000000002_1.jpg
00000000000003_1.jpg

and so on

Zanna
  • 70,465

2 Answers2

4

Adapted from one of Oli's answers:

rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *

This takes every file in the current directory and renames it with a number with 14 digits (I hope I counted correctly) followed by _1.jpg. our $i introduces a global variable i, which is then increased by one and printed with sprintf. e commands rename to evaluate the right side of the replacement (= everything between the second and the third /) as an expression rather than literally. If you're happy with the results, remove -n to perform the renaming.

If you want to dive into perl expressions and their beauty, the perldoc is the way to go.

dessert
  • 39,982
3

Would this works for you :

i=1
for file in *; do
    mv "$file" "$(printf %014d $i)_1.jpg"
    i=$((i+1))
done

It will rename every file in the current directory like this :

00000000000001_1.jpg
.
.
00000000000009_1.jpg
.
.
00000000000010_1.jpg
.
.
Paul
  • 251