Skip to content

Using Linux rename tool – bit of improvement

12 February 2019

In the previous post, I shared some ideas about renaming — one of the daily repetitive tasks. From time to time it is required to do this on a variety of files at once. So here is a bit of improvement that I ended up with and found it useful. Hope this to help to pop up better ideas around.

Instead of using wildcards to define which flies we want to be changed, rename might be applied on a dynamic list, leaving the other files intact.

One of the options to build such a list is the find command. The result (what found) will be used by rename. So here how it goes:

find -iregex '.*\.jpe?g$' -exec rename 'y/A-Z/a-z/ | s/ /_/g | s/jpeg$/jpg/ig' {} +

I didn’t find a way to rename files regardless of the case, so instead, I used -iregex (ignore case regex) to filter the list of files. Any valid regex might be used there. Then used -exec to fire renaming. The filter is the same. The difference is only the brackets with a plus at the end {} +. That means “whatever the output list find supplies”, apply command (rename in the case) to each one.

I hope you’ll find this helpful.

From → Linux, Tips

Leave a comment