With rename
command,
rename 's/-[^-]+\.jpg$/.jpg/' *.jpg
(OR)
With bash
one liner,
for file in *.jpg; do mv "$file" "${file%-*}.jpg" ; done
Instead of *.jpg
you can specify list of file names which you want to rename.
Question
I have the below file names:
file-photo01-dfakdj.jpg
file-photo02-bjkadf.jpg
file-photo03-annunioo.jpg
...
How to use rename
command or other bash command to rename those file names to:
file-photo01.jpg
file-photo02.jpg
file-photo03.jpg
...
Solution
With rename
command,
rename 's/-[^-]+\.jpg$/.jpg/' *.jpg
(OR)
With bash
one liner,
for file in *.jpg; do mv "$file" "${file%-*}.jpg" ; done
Instead of *.jpg
you can specify list of file names which you want to rename.