Has rename syntax changed?

L A Walsh cygwin@tlinx.org
Wed Mar 4 10:42:00 GMT 2020


On 2020/03/03 15:45, Hans-Bernhard Bröker wrote:
> Am 04.03.2020 um 00:25 schrieb L A Walsh:
>   
>> On 2020/02/28 04:38, Fergus Daly wrote:
>>     
>>> 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 
>>> any filename in *.ext in the current directory.
>>>       
>> isn't that they same as "mv anything.xxx Anything.xxx" ?
>>     
>
> No.  For three reasons:
>
> *) it's .ext, not .xxx :-)
> *) it will find and replace 'anything' _anywhere_in_ the filename, not 
> just in the basename.
>   
I'm confused about your terminology. If you type 'man basename', you'll
see something that is essentially this:

    basename = [optional directory name '/'] basename [. extension (or 
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 
basename
are the same after it matched the listed 'extension', no?

Second, rename doesn't replace the string '_anywhere_' in the filename, 
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



More information about the Cygwin mailing list