1). Using Linux find
command
Using find
command to rename all .oldext files under directory structure with a new extension: .newext
find . -type f -name "*.oldext" -exec rename 's/\.oldext$/.newext/' '{}' \;
2). Using Linux find
command, but in a different approach
for f in `find . -iname '*.oldext' -type f -print`;do mv "$f" ${f%.oldext}.newext; done
3. Using util-linux rename command rename.ul
On Ubuntu 18.04 +, the util-linux rename command is available as rename.ul
:
rename.ul -o -v .oldext .newext *.oldext
Here is an example command I used occasionally to rename movie subtitles:
rename.ul -o -v .srt .rum.srt *.srt
Result
`Westworld.S03E01.Parce.Domine.1080p.srt' -> `Westworld.S03E01.Parce.Domine.1080p.rum.srt'
`Westworld.S03E02.The.Winter.Line.1080p.srt' -> `Westworld.S03E02.The.Winter.Line.1080p.rum.srt'
`Westworld.S03E03.The.Absence.of.Field.1080p.srt' -> `Westworld.S03E03.The.Absence.of.Field.1080p.rum.srt'
4). Using the mv
command together with for
, as a native bash script:
for x in *.oldext; do mv "$x" "`basename "$x" .oldext`.newext"; done
Final conclusion:
it is noted that using
rename.ul
is the simplest and most intuitive way to rename the extension of several files simultaneously in Linux, in this case Ubuntu!
Leave a Reply
Your email address will not be published. Required fields are marked *