문제

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
...
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top