Skip to content
Advertisement

Rename part of filename using regex

I have a bunch of files where there is additional information in square brackets. I would like to rename them by removing that section.

For example:

JavaScript

Want to rename to:

JavaScript

I tried playing with regex (and using the rename command) but without success. Does anybody know a way to have the rename command strip of only the part of ” [….]” (including the leading space).

Advertisement

Answer

Looping for each file and using sed for some simple regex matching:

JavaScript

Tested with:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement