Search code examples
bashunixglob

How to make a reference to what was matched in glob pattern


With regexes you can put a capturing group and refer to it in your action (i.e. \1). Is there something similar for when glob is used in bash?

Say I have files named 'file1', 'file2', 'file3', and I want to rename them to 'foo1', 'foo2', 'foo3'. I'd like to do something like this:

mv file(?) foo\1

is that possible?


Solution

  • You're looking for batch renaming. There are a lot of solutions here on stackoverflow. Here is one example