public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Has rename syntax changed?
@ 2020-02-28 12:38 Fergus Daly
  2020-02-28 18:09 ` Lee
  2020-03-04  3:52 ` L A Walsh
  0 siblings, 2 replies; 9+ messages in thread
From: Fergus Daly @ 2020-02-28 12:38 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'; +Cc: Fergus Daly

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.
What I remember as past behaviour now fails, leaving he filename unaltered.
(Failure in much the same way as mv would fail if the similar attempt was made.)
(Good old DOS command rename (or the abbreviation ren) used to achieve multiple-rename in an easy manner that just eludes bash.)
Anyway: has something altered (and quite recently, i think), or am I just mis-remembering the versatility of the command rename?
Fergus  

--
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Has rename syntax changed?
  2020-02-28 12:38 Has rename syntax changed? Fergus Daly
@ 2020-02-28 18:09 ` Lee
  2020-02-28 19:52   ` Brian Inglis
  2020-02-29  8:27   ` Fergus Daly
  2020-03-04  3:52 ` L A Walsh
  1 sibling, 2 replies; 9+ messages in thread
From: Lee @ 2020-02-28 18:09 UTC (permalink / raw)
  To: cygwin; +Cc: Fergus Daly

On 2/28/20, 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.
> What I remember as past behaviour now fails, leaving he filename unaltered.
> (Failure in much the same way as mv would fail if the similar attempt was
> made.)
> (Good old DOS command rename (or the abbreviation ren) used to achieve
> multiple-rename in an easy manner that just eludes bash.)
> Anyway: has something altered (and quite recently, i think), or am I just
> mis-remembering the versatility of the command rename?

Try it with the '-v' option

$ rename -v anything AnyThing *.ext
`anything.ext' -> `AnyThing.ext'
`xxanythingxx.ext' -> `xxAnyThingxx.ext'

$ rename -v AnyThing anything *.exe
rename: *.exe: not accessible: No such file or directory

$ rename -v AnyThing anything *.ext
`AnyThing.ext' -> `anything.ext'
`xxAnyThingxx.ext' -> `xxanythingxx.ext'

Lee

--
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Has rename syntax changed?
  2020-02-28 18:09 ` Lee
@ 2020-02-28 19:52   ` Brian Inglis
  2020-02-29  8:27   ` Fergus Daly
  1 sibling, 0 replies; 9+ messages in thread
From: Brian Inglis @ 2020-02-28 19:52 UTC (permalink / raw)
  To: cygwin

On 2020-02-28 11:09, Lee wrote:
> On 2/28/20, 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.
>> What I remember as past behaviour now fails, leaving he filename unaltered.
>> (Failure in much the same way as mv would fail if the similar attempt was
>> made.)
>> (Good old DOS command rename (or the abbreviation ren) used to achieve
>> multiple-rename in an easy manner that just eludes bash.)
>> Anyway: has something altered (and quite recently, i think), or am I just
>> mis-remembering the versatility of the command rename?
> 
> Try it with the '-v' option
> 
> $ rename -v anything AnyThing *.ext
> `anything.ext' -> `AnyThing.ext'
> `xxanythingxx.ext' -> `xxAnyThingxx.ext'
> 
> $ rename -v AnyThing anything *.exe
> rename: *.exe: not accessible: No such file or directory
> 
> $ rename -v AnyThing anything *.ext
> `AnyThing.ext' -> `anything.ext'
> `xxAnyThingxx.ext' -> `xxanythingxx.ext'

This will always depend on the file system interface: DOS ignores case changes
as case is not supported, ExFAT/VFAT and everything else preserves case changes,
as do most remote file systems, unless the remote is set up case insensitively
to check the old and new names and ignore case changes (I've been annoyed by
that in the past, normally on proprietary file servers).

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: Has rename syntax changed?
  2020-02-28 18:09 ` Lee
  2020-02-28 19:52   ` Brian Inglis
@ 2020-02-29  8:27   ` Fergus Daly
  2020-02-29 15:48     ` Brian Inglis
  1 sibling, 1 reply; 9+ messages in thread
From: Fergus Daly @ 2020-02-29  8:27 UTC (permalink / raw)
  To: cygwin; +Cc: Fergus Daly, Lee

> $ rename "anything" "AnyThing" *.ext
> What I remember as past behaviour now fails, leaving he filename unaltered.

>> Try it with the '-v' option

So I did:

$ touch "This is the test file"
$ ls -al
-rw-r--r-- 1    0 Feb 29 08:10 This is the test file
$ rename -v " the " " The " *
`This is the test file' -> `This is The test file'
$ ls -al
-rw-r--r-- 1    0 Feb 29 08:10 This is the test file

Filename unaltered, contrary to verbose confirmation.
Just checking: in DOS Command Prompt box, dir also shows filename unaltered. 
BTW failure consistent on both FAT32 and exFAT filesystems; but the rename command _works_as_expected_ on NTFS.
I get the subtle distinctions between FAT (all versions) and NTFS platforms; but, all the same, the rename command surely worked on *FAT* in the past - I would have noticed if it didn't because I toggle lc <> UC quite a lot.

Fergus




--
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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Has rename syntax changed?
  2020-02-29  8:27   ` Fergus Daly
@ 2020-02-29 15:48     ` Brian Inglis
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Inglis @ 2020-02-29 15:48 UTC (permalink / raw)
  To: cygwin

On 2020-02-29 01:27, Fergus Daly wrote:
>> $ rename "anything" "AnyThing" *.ext
>> What I remember as past behaviour now fails, leaving he filename unaltered.
> 
>>> Try it with the '-v' option
> 
> So I did:
> 
> $ touch "This is the test file"
> $ ls -al
> -rw-r--r-- 1    0 Feb 29 08:10 This is the test file
> $ rename -v " the " " The " *
> `This is the test file' -> `This is The test file'
> $ ls -al
> -rw-r--r-- 1    0 Feb 29 08:10 This is the test file
> 
> Filename unaltered, contrary to verbose confirmation.
> Just checking: in DOS Command Prompt box, dir also shows filename unaltered. 
> BTW failure consistent on both FAT32 and exFAT filesystems; but the rename command _works_as_expected_ on NTFS.

How that works will depend on the available VFAT LFN support on that filesystem.

> I get the subtle distinctions between FAT (all versions) and NTFS platforms; but, all the same, the rename command surely worked on *FAT* in the past - I would have noticed if it didn't because I toggle lc <> UC quite a lot.

You're not really giving us much that may help you, about what Windows and
Cygwin releases you're running, whether the file systems are local devices, or
on what type of remote system, what drive (USB 1/2/3/C, CF1/2, full/mini/micro
SD/SDHC/SDXC, makes, models, capacities), underlying formats, and driver types.

IIRC and I may not, you may be able to change case if you jump thru hoops and
also change the underlying 8.3 name at the same time e.g. rename "This is the
test file" to "This is The test file.txt" then "This is The test file"; perhaps
like:

$ rename -v "the test file" "The test file.txt" "This is the test file"
$ rename -v "The test file.txt" "The test file" "This is the test file.txt"

While rename can be useful for multiple files, for single files, and other
simple commands, I use bash filename completion on long file names, and editline
copy/paste to add brace expansions:

	$ mv -v This\ is\ {the\ test\ file,The\ test\ file.txt}
	$ mv -v This\ is\ {The\ test\ file.txt,The\ test\ file}
	$ touch -chr file.{ref,new}
	$ gcc -g -Og -Wall -Wextra -o test{,.c}

Check the type of the target filesystem using available tools to see if anything
changed and/or can be changed. If remote, check that system's filesystem driver
for any changes. From an elevated command prompt try e.g.

> fsutil fsinfo volumeinfo g:
Volume Name :
Volume Serial Number : 0x6d26aae6
Max Component Length : 255
File System Name : NTFS
Is ReadWrite
Not Thinly-Provisioned
Supports Case-sensitive filenames
Preserves Case of filenames
Supports Unicode in filenames
Preserves & Enforces ACL's
Supports file-based Compression
Supports Disk Quotas
Supports Sparse files
Supports Reparse Points
Returns Handle Close Result Information
Supports POSIX-style Unlink and Rename
Supports Object Identifiers
Supports Encrypted File System
Supports Named Streams
Supports Transactions
Supports Hard Links
Supports Extended Attributes
Supports Open By FileID
Supports USN Journal

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Has rename syntax changed?
  2020-02-28 12:38 Has rename syntax changed? Fergus Daly
  2020-02-28 18:09 ` Lee
@ 2020-03-04  3:52 ` L A Walsh
  2020-03-04  5:09   ` Hans-Bernhard Bröker
  1 sibling, 1 reply; 9+ messages in thread
From: L A Walsh @ 2020-03-04  3:52 UTC (permalink / raw)
  To: Fergus Daly, cygwin

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" ?


> What I remember as past behaviour now fails, leaving he filename unaltered.
>   

/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 anything.xxx
/tmp> rename any Any *.xxx
/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 Anything.xxx
---
    Works here on a local NTFS file system.
> (Failure in much the same way as mv would fail if the similar attempt was made.)
>   
----
???
Like this?:

/tmp> touch anything.xxx
/tmp> mv anything.xxx Anything.xxx
/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 Anything.xxx
/tmp> rename Any any *.xxx
> (Good old DOS command rename (or the abbreviation ren) used to achieve multiple-rename in an easy manner that just eludes bash.)
>   
---
    'rename' is not a bash builtin or feature, neither is 'mv' nor
my preference: 'mmv':

/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 anything.xxx
/tmp> mmv 'a*.xxx' 'A#1.xxx'      #(same as "mmv a\*.xxx A\#1.xxx' )
/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 Anything.xxx

FWIW: w/mmv, meta chars like '*' in source and '#' in target need to be
quoted to protect from shell expansion.

> Anyway: has something altered (and quite recently, i think), or am I just mis-remembering the versatility of the command rename?
>   
----
    I think that the 'whatever' that has changed is likely a different
file system.

    Besides the above tests/examples on Win7/NTFS, I got similar results
on a network share from a Linux-Samba server.

Oh -- one more potential gotcha:

the '*.xxx' pattern you are giving to rename is subject to shell
expansion (shell being bash in this case).  If the *.xxx doesn't
match all your targets and bash doesn't have 'nocaseglob' set, you
can get:

/tmp> shopt -u nocaseglob nocasematch
/tmp> rename Anything anything *.xxx
rename: *.xxx: not accessible: No such file or directory
/tmp> shopt -s nocaseglob nocasematch
/tmp> rename Anything anything *.xxx

Why?: because my filename was 'Anything.Xxx' (Anything.XXX would do the 
same).

Even though the file system ignores case, if bash is told
not to ignore case, the '*.xxx' won't match anything but all lower
case extensions.

It's a contrived case, but illustrates that the pattern at
the end isn't seen by 'rename' because it is 1st expanded by bash.

Hope this helps, and isn't overkill! ;-)





--
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Has rename syntax changed?
  2020-03-04  3:52 ` L A Walsh
@ 2020-03-04  5:09   ` Hans-Bernhard Bröker
  2020-03-04 10:42     ` L A Walsh
  0 siblings, 1 reply; 9+ messages in thread
From: Hans-Bernhard Bröker @ 2020-03-04  5:09 UTC (permalink / raw)
  To: cygwin

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.
*) it will do so on _all_ files in the cwd matching '*.ext', not just a 
single one --- that's its entire purpose.

--
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Has rename syntax changed?
  2020-03-04  5:09   ` Hans-Bernhard Bröker
@ 2020-03-04 10:42     ` L A Walsh
  2020-03-05 10:33       ` Hans-Bernhard Bröker
  0 siblings, 1 reply; 9+ messages in thread
From: L A Walsh @ 2020-03-04 10:42 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Has rename syntax changed?
  2020-03-04 10:42     ` L A Walsh
@ 2020-03-05 10:33       ` Hans-Bernhard Bröker
  0 siblings, 0 replies; 9+ messages in thread
From: Hans-Bernhard Bröker @ 2020-03-05 10:33 UTC (permalink / raw)
  To: cygwin

Am 04.03.2020 um 04:52 schrieb L A Walsh:
> 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. 

The terminology is fine, but the statement isn't quite.  That had better 
have read:

 >> it will find and replace 'anything' _anywhere_in_ the filename, not
 >> just if that's the entire basename.

> You said all of the filenames must match '*.ext'.  

No, I didn't.  I said that rename will work on all files in the cwd 
matching *.ext.  Files in the cwd not matching *.ext will be left alone.

--
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-03-04 19:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28 12:38 Has rename syntax changed? Fergus Daly
2020-02-28 18:09 ` Lee
2020-02-28 19:52   ` Brian Inglis
2020-02-29  8:27   ` Fergus Daly
2020-02-29 15:48     ` Brian Inglis
2020-03-04  3:52 ` L A Walsh
2020-03-04  5:09   ` Hans-Bernhard Bröker
2020-03-04 10:42     ` L A Walsh
2020-03-05 10:33       ` Hans-Bernhard Bröker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).