rename Files on linux

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 *.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!

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *