From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2910 invoked by alias); 4 Mar 2020 03:52:43 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 2897 invoked by uid 89); 4 Mar 2020 03:52:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: Ishtar.sc.tlinx.org Received: from ishtar.tlinx.org (HELO Ishtar.sc.tlinx.org) (173.164.175.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Mar 2020 03:52:42 +0000 Received: from [192.168.3.12] (Athenae [192.168.3.12]) by Ishtar.sc.tlinx.org (8.14.7/8.14.4/SuSE Linux 0.8) with ESMTP id 0243qc2k071807 for ; Tue, 3 Mar 2020 19:52:40 -0800 Message-ID: <5E5F2606.3070201@tlinx.org> Date: Wed, 04 Mar 2020 10:42:00 -0000 From: L A Walsh User-Agent: Thunderbird MIME-Version: 1.0 To: cygwin@cygwin.com Subject: Re: Has rename syntax changed? References: <5E5EE76B.8000202@tlinx.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2020-03/txt/msg00065.txt On 2020/03/03 15:45, Hans-Bernhard Br=C3=B6ker wrote: > Am 04.03.2020 um 00:25 schrieb L A Walsh: >=20=20=20 >> On 2020/02/28 04:38, Fergus Daly wrote: >>=20=20=20=20=20 >>> I am almost certain that the command >>> $ rename "anything" "AnyThing" *.ext >>> would alter the string from lc to uc as shown, anywhere it occurred in= =20 >>> any filename in *.ext in the current directory. >>>=20=20=20=20=20=20=20 >> isn't that they same as "mv anything.xxx Anything.xxx" ? >>=20=20=20=20=20 > > No. For three reasons: > > *) it's .ext, not .xxx :-) > *) it will find and replace 'anything' _anywhere_in_ the filename, not=20 > just in the basename. >=20=20=20 I'm confused about your terminology. If you type 'man basename', you'll see something that is essentially this: basename =3D [optional directory name '/'] basename [. extension (or=20 suffix)] You said we are only working in 'cwd' so there is no directory name. You said all of the filenames must match '*.ext'. The only part left after the extension, ".ext", is removed is the basename. So while your replacement can match _anywhere_in_ the filename, the filename and=20 basename are the same after it matched the listed 'extension', no? Second, rename doesn't replace the string '_anywhere_' in the filename,=20 but only the first occurance: > rename anything AnyThing *.ext > ll *.ext -rw-rw-rw-+ 1 0 Mar 3 19:24 oneAnyThingtwo.ext -rw-rw-rw-+ 1 0 Mar 3 19:25 oneAnyThingtwoanythingthree.ext While bash only works on 1 file at a time, it can replace 1 or multiple occurances: > for f in *.ext;do > mv "$f" "${f//anything/AnyThing}" > done > ll *.ext -rw-rw-rw-+ 1 0 Mar 3 19:24 oneAnyThingtwo.ext -rw-rw-rw-+ 1 0 Mar 3 19:25 oneAnyThingtwoAnyThingthree.ext If one wants to replace 1 occurance in multiple files, I would still use 'mmv', as rename will overwrite files if there is a collision whereas 'mmv' won't. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple