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.
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.
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.
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.
-e
. With a smart shell you could just runmv "${f}" "${f/?/ICON}"
– don_crissti Sep 21 '18 at 14:25