0

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.

0

2 Answers 2

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.

0
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.

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

Not the answer you're looking for? Browse other questions tagged .