Reputation: 47
I am trying to create a script that will rename all the files in a directory with an extension of .jpg. I figure that I would have to find the total number of files with the .jpg extension and iterate through all the files in the directory using a for loop. My question is, how would I go about getting the total number of files with the .jpg extension within a directory?
Thank you!
Upvotes: 1
Views: 954
Reputation: 123570
There's no reason to count the number of files in advance.
#!/bin/bash
i=1
for file in *.jpg
do
mv -i "$file" "$i.jpg"
(( i++ ))
done
Upvotes: 2