There are two versions of rename
in common use. If you've the perl
one, sometimes also known as prename
, the syntax uses a Regular Expression embedded into a perl
operation such as "substitute". To remove the fifth character you need to match on the first four, and then any remaining from character six onwards.
Here's an appropriate RE. The first bracketed expression matches an optional path component. The second matches the beginning of the filename. We don't need to match the end of the filename as well not be changing anything in it, and it's not needed as an anchor.
^(.*/)?(....).
A dot corresponds to "any character". The uparrow binds to the start-of-string. A .*
sequence means "zero or more characters". A question mark allows the preceding segment to be optional. The bracketed sections can be reapplied in the matching part as $1
, $2
, etc.
Putting this into the "substitute" command (s
) for all files matching the glob *.mp3
you get this:
rename 's/^(.*/)?(....)./$1$2/' ./*.mp3