0

This question already has an answer here:

I would like to rename these files;

2000.jpg
B001.jpg 
9002.jpg
D006.jpg

to these names below

ICON000.jpg 
ICON001.jpg 
ICON002.jpg 
ICON006.jpg

respectively.

marked as duplicate by roaima, user88036, αғsнιη, Jeff Schaller, RalfFriedl Sep 21 '18 at 16:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

With prename (or similar with file-rename):

prename -n 's/^[^\d]+/ICON/' *.jpg

This will replace non-digit characters to ICON.

Output:

A000.jpg renamed as ICON000.jpg
B001.jpg renamed as ICON001.jpg
C002.jpg renamed as ICON002.jpg
D006.jpg renamed as ICON006.jpg

Remove the -n to perform the action.

1

If you have the rename utility, read the man page on how to do string replacement.

If you do not have the rename utility, use some kind of for loop to do the renaming. Something like the following should work:

for f in *.jpg; do
    mv ${f} $(echo ${f} | sed -e 's#^.#ICON#')
done

The sed command is just replacing the first character with the string ICON.

  • 2
    The anchoring is superfluous here. So is the -e. With a smart shell you could just run mv "${f}" "${f/?/ICON}" – don_crissti Sep 21 '18 at 14:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.