On Mon, Jan 16, 2023 at 11:07 AM Simon Becherer <simon@becherer.de> wrote:
Hi,
i have to rename hunderts of files: 792041_100029699.mi 792090_100029501.mi . . . to 792041.mi 792090.mi . . .
i tried: rename ??????_*.mi ??????.mi *.mi
There are at least two commands "rename", one from util-linux and another Perl based rename, and this invocation is wrong for both of them.
rename: ??????_.mi: kein Zugriff: Datei oder Verzeichnis nicht gefunden as you see, no sucess.
(first file is gone, all others stay as they are)
And what did you expect? The pattern is expanded by shell before your command even sees it, and it ends by moving the first file onto the second file and skipping all the rest. Because your command becomes rename 792041_100029699.mi 792090_100029501.mi ... ??????.mi 792041_100029699.mi 792090_100029501.mi ... and the first two arguments are source and target replacement, so the name 792041_100029699.mi is replaced by 792090_100029501.mi.
is there a easy way to do this (without writing a script)?
And without reading and understanding documentation? I doubt it. It is not possible with the util-linux version which does pure string substitution. It is possible with the Perl version but you need to understand Perl regular expressions at which point you can just as well write the script. Actually, the internet is full of the same question and detailed examples of how to do it. If you are banned by Google https://stackoverflow.com/questions/6840332/rename-multiple-files-by-replaci...