Am 16.01.23 um 11:12 schrieb Andrei Borzenkov:
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...
Hi andrei, well i was thinking about something similar to the dos "rename" command: ren *.mi ??????.mi should (if i remember correct) work in the dos days. and i am sorry, i have never understood the deeper internals of patterns/expressions how they get expanded in shell. i have read, but as more i read as more unclear it get to me. and i need this only a couple of times a year. so i forget the most when i need next time. for me its a lot of googeling and try and error if my scripts need something of this. so i was asking here. thanks for your online "script" simoN -- www.becherer.de ----------------------------------------------- - Das ist die vorlaeufig endgueltige Version! - Herbert C. Maier Dipl.-Ing. (FH) -----------------------------------------------