zsh-users
 help / color / mirror / code / Atom feed
* newbie rm --^file question
@ 2016-12-25 19:22 Hoji, Akihiko
  2016-12-25 20:45 ` Gabor Maghera
  2016-12-25 21:10 ` Bart Schaefer
  0 siblings, 2 replies; 9+ messages in thread
From: Hoji, Akihiko @ 2016-12-25 19:22 UTC (permalink / raw)
  To: zsh-users

Hi, 


I am trying to delete all the files except a few files having the same file extension.  I did the following;

setopt extended glob
rm -rf —^file.ext.*

This gives an error message, “zsh, no matches found:”

I would appreciate a poster as to what I am doing wrong. 

Thanks in advance. 

AH

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

* Re: newbie rm --^file question
  2016-12-25 19:22 newbie rm --^file question Hoji, Akihiko
@ 2016-12-25 20:45 ` Gabor Maghera
  2016-12-25 20:49   ` Hoji, Akihiko
  2016-12-25 21:10 ` Bart Schaefer
  1 sibling, 1 reply; 9+ messages in thread
From: Gabor Maghera @ 2016-12-25 20:45 UTC (permalink / raw)
  To: Hoji, Akihiko, zsh-users

[-- Attachment #1: Type: text/plain, Size: 716 bytes --]

Not sure if it's some nuance with different versions of zsh we're running,
but I needed to "setopt exended_glob" (with the underscore).  But I think
the main issue here is the globbing syntax.

Have a look at a working example here: https://asciinema.org/a/97273

Merry Christmas,
Gabor



On Sun, Dec 25, 2016 at 11:22 AM Hoji, Akihiko <akh22@pitt.edu> wrote:

> Hi,
>
>
> I am trying to delete all the files except a few files having the same
> file extension.  I did the following;
>
> setopt extended glob
> rm -rf —^file.ext.*
>
> This gives an error message, “zsh, no matches found:”
>
> I would appreciate a poster as to what I am doing wrong.
>
> Thanks in advance.
>
> AH

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

* Re: newbie rm --^file question
  2016-12-25 20:45 ` Gabor Maghera
@ 2016-12-25 20:49   ` Hoji, Akihiko
  2016-12-25 20:51     ` Gabor Maghera
  0 siblings, 1 reply; 9+ messages in thread
From: Hoji, Akihiko @ 2016-12-25 20:49 UTC (permalink / raw)
  To: Gabor Maghera; +Cc: zsh-users

I forgot to mention this.  I am using zsh 5.3.1 (x86_64-apple-darwin16.3.0) and OS X 10.12.2


AH  


> On Dec 25, 2016, at 3:45 PM, Gabor Maghera <gmaghera@gmail.com> wrote:
> 
> Not sure if it's some nuance with different versions of zsh we're running,
> but I needed to "setopt exended_glob" (with the underscore).  But I think
> the main issue here is the globbing syntax.
> 
> Have a look at a working example here: https://asciinema.org/a/97273
> 
> Merry Christmas,
> Gabor
> 
> 
> 
> On Sun, Dec 25, 2016 at 11:22 AM Hoji, Akihiko <akh22@pitt.edu> wrote:
> 
>> Hi,
>> 
>> 
>> I am trying to delete all the files except a few files having the same
>> file extension.  I did the following;
>> 
>> setopt extended glob
>> rm -rf —^file.ext.*
>> 
>> This gives an error message, “zsh, no matches found:”
>> 
>> I would appreciate a poster as to what I am doing wrong.
>> 
>> Thanks in advance.
>> 
>> AH


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

* Re: newbie rm --^file question
  2016-12-25 20:49   ` Hoji, Akihiko
@ 2016-12-25 20:51     ` Gabor Maghera
  0 siblings, 0 replies; 9+ messages in thread
From: Gabor Maghera @ 2016-12-25 20:51 UTC (permalink / raw)
  To: Hoji, Akihiko; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1502 bytes --]

Perfect!  Your environment is identical to mine (as far as zsh an macOS
versions go).  The command in the example should work for you as well,
unless I misunderstood the question.

❯ uname -a
Darwin FOLSML-R5TYG8W 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17
20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64

~
❯ zsh --version
zsh 5.3.1 (x86_64-apple-darwin16.3.0)

--
Gabor

On Sun, Dec 25, 2016 at 12:49 PM Hoji, Akihiko <akh22@pitt.edu> wrote:

> I forgot to mention this.  I am using zsh 5.3.1
> (x86_64-apple-darwin16.3.0) and OS X 10.12.2
>
>
> AH
>
>
> > On Dec 25, 2016, at 3:45 PM, Gabor Maghera <gmaghera@gmail.com> wrote:
> >
> > Not sure if it's some nuance with different versions of zsh we're
> running,
> > but I needed to "setopt exended_glob" (with the underscore).  But I think
> > the main issue here is the globbing syntax.
> >
> > Have a look at a working example here: https://asciinema.org/a/97273
> >
> > Merry Christmas,
> > Gabor
> >
> >
> >
> > On Sun, Dec 25, 2016 at 11:22 AM Hoji, Akihiko <akh22@pitt.edu> wrote:
> >
> >> Hi,
> >>
> >>
> >> I am trying to delete all the files except a few files having the same
> >> file extension.  I did the following;
> >>
> >> setopt extended glob
> >> rm -rf —^file.ext.*
> >>
> >> This gives an error message, “zsh, no matches found:”
> >>
> >> I would appreciate a poster as to what I am doing wrong.
> >>
> >> Thanks in advance.
> >>
> >> AH
>
>

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

* Re: newbie rm --^file question
  2016-12-25 19:22 newbie rm --^file question Hoji, Akihiko
  2016-12-25 20:45 ` Gabor Maghera
@ 2016-12-25 21:10 ` Bart Schaefer
  2016-12-25 21:49   ` Akihiko Hohji
  1 sibling, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2016-12-25 21:10 UTC (permalink / raw)
  To: zsh-users

On Dec 25,  7:22pm, Hoji, Akihiko wrote:
}
} setopt extended glob

If you literally did that, you should have gotten an error message; there
is no option named "extended" although there is one named "glob".

You can use underscores or hyphens between words (actually, between any
two letters) in option names, but not spaces.

setopt extendedglob
setopt extended_glob
setopt extended-glob
setopt EX_tend-ed_GLOB

} rm -rf -^file.ext.*

Is there a space missing there between the second "-" and the "^" ?  Or
do the files you want to remove really have names beginning with "-" ?

} I would appreciate a poster as to what I am doing wrong. 

Other than misplaced spacing, you seem to have it; see Gabor's example.


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

* Re: newbie rm --^file question
  2016-12-25 21:10 ` Bart Schaefer
@ 2016-12-25 21:49   ` Akihiko Hohji
  2016-12-25 22:47     ` Gabor Maghera
  0 siblings, 1 reply; 9+ messages in thread
From: Akihiko Hohji @ 2016-12-25 21:49 UTC (permalink / raw)
  To: Bart Schaefer, Gabor Maghera; +Cc: zsh-users

Sorry.  Actually extended glob was due to auto-correction by Apple Mail.  I really typed in setopt extendedglob.

Either rm -rf with double “-“ ^file.ext.* or a single “-“ does not work.  I get the same “no matches found” message.  And there is no space in between “-“.  I’ve gotten this approach with the double “-“ from a post in Stackoverflow.  If I don’t add “*” at the end or begging of file name, it works fine.  

To just give you more details, the following is the list of files in  /System/Library/Caches;

drwxr-xr-x  16 root  wheel   544B Dec 16 21:53 .
drwxr-xr-x  92 root  wheel   3.1K Dec 16 09:31 ..
drwxr-xr-x   6 root  wheel   204B Dec 15 21:47 com.apple.CVMS
-rw-r--r--   1 root  wheel    42K Oct  4 21:52 com.apple.Components2.SystemCache.Components
-rw-r--r--   1 root  wheel    57K Sep 13 20:49 com.apple.Components2.SystemCache.QuickTimeComponents
-rw-r--r--   1 root  wheel   8.6K Dec 16 09:31 com.apple.IntlDataCache.le
-rw-r--r--   1 root  wheel    78K Dec 16 09:31 com.apple.IntlDataCache.le.kbdx
-rw-r--r--   1 root  wheel    21K Dec 16 09:35 com.apple.app-sandbox-cache.plist
-rw-r--r--   1 root  wheel    41B Dec 16 09:32 com.apple.bootefisignature
drwxr-xr-x   3 root  wheel   102B Dec 15 21:36 com.apple.bootstamps
drwxr-xr-x   2 root  wheel    68B Dec 15 21:36 com.apple.corestorage
drwx------   3 root  wheel   102B Dec 17 22:30 com.apple.coresymbolicationd
drwxr-xr-x   4 root  wheel   136B Dec 15 21:36 com.apple.kext.caches
-rw-r--r--@  1 root  wheel    23K Dec 16 21:53 com.apple.preferencepanes.systemcache
-rw-r--r--   1 root  wheel    11K Dec 16 09:35 com.apple.xpc.extensions.cache
-rw-r--r--   1 root  wheel   203K Dec 16 09:35 com.apple.xpchelper.cache

I’d like to get rid of directories and files except com.apple.IntlDataCche.le and com.apple.IntlDataCche.le.kbdx.  

And I did;

setopt extendedglob
rm -rf -^com.apple.IntlDataCache.*

Then I get zsh: no matches found: -^com.apple.IntlDataCache.le.*

Again my system is 

sw_vers
ProductName:	Mac OS X
ProductVersion:	10.12.2
BuildVersion:	16C67 

Thanks.  

AH

> On Dec 25, 2016, at 4:10 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
> On Dec 25,  7:22pm, Hoji, Akihiko wrote:
> }
> } setopt extended glob
> 
> If you literally did that, you should have gotten an error message; there
> is no option named "extended" although there is one named "glob".
> 
> You can use underscores or hyphens between words (actually, between any
> two letters) in option names, but not spaces.
> 
> setopt extendedglob
> setopt extended_glob
> setopt extended-glob
> setopt EX_tend-ed_GLOB
> 
> } rm -rf -^file.ext.*
> 
> Is there a space missing there between the second "-" and the "^" ?  Or
> do the files you want to remove really have names beginning with "-" ?
> 
> } I would appreciate a poster as to what I am doing wrong. 
> 
> Other than misplaced spacing, you seem to have it; see Gabor's example.


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

* Re: newbie rm --^file question
  2016-12-25 21:49   ` Akihiko Hohji
@ 2016-12-25 22:47     ` Gabor Maghera
  2016-12-25 23:02       ` Akihiko Hohji
  0 siblings, 1 reply; 9+ messages in thread
From: Gabor Maghera @ 2016-12-25 22:47 UTC (permalink / raw)
  To: Akihiko Hohji, Bart Schaefer; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 3952 bytes --]

That "--" causes rm to stop looking for flags.  It is handy if the file
pattern argument supplied to rm includes '-' characters.  See the man page
for the rm command, it's explained towards the end.

You don't really need it for what you are doing, but if you would like to
use it, it is a separate argument from the file or globbing pattern:

Try:

rm -rf -- ^com.apple.IntlDataCache.*

And here is an example where you do need to use the "--" argument:

❯ ls
-o      bar.ext foo     foo.ext

~/example/abc
❯ rm -o
rm: illegal option -- o
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file

~/example/abc
❯ rm -- -o

~/example/abc
❯ ls
bar.ext foo     foo.ext

~/example/abc

On Sun, Dec 25, 2016 at 1:49 PM Akihiko Hohji <akhst7@me.com> wrote:

> Sorry.  Actually extended glob was due to auto-correction by Apple Mail.
> I really typed in setopt extendedglob.
>
> Either rm -rf with double “-“ ^file.ext.* or a single “-“ does not work.
> I get the same “no matches found” message.  And there is no space in
> between “-“.  I’ve gotten this approach with the double “-“ from a post in
> Stackoverflow.  If I don’t add “*” at the end or begging of file name, it
> works fine.
>
> To just give you more details, the following is the list of files in
> /System/Library/Caches;
>
> drwxr-xr-x  16 root  wheel   544B Dec 16 21:53 .
> drwxr-xr-x  92 root  wheel   3.1K Dec 16 09:31 ..
> drwxr-xr-x   6 root  wheel   204B Dec 15 21:47 com.apple.CVMS
> -rw-r--r--   1 root  wheel    42K Oct  4 21:52
> com.apple.Components2.SystemCache.Components
> -rw-r--r--   1 root  wheel    57K Sep 13 20:49
> com.apple.Components2.SystemCache.QuickTimeComponents
> -rw-r--r--   1 root  wheel   8.6K Dec 16 09:31 com.apple.IntlDataCache.le
> -rw-r--r--   1 root  wheel    78K Dec 16 09:31
> com.apple.IntlDataCache.le.kbdx
> -rw-r--r--   1 root  wheel    21K Dec 16 09:35
> com.apple.app-sandbox-cache.plist
> -rw-r--r--   1 root  wheel    41B Dec 16 09:32 com.apple.bootefisignature
> drwxr-xr-x   3 root  wheel   102B Dec 15 21:36 com.apple.bootstamps
> drwxr-xr-x   2 root  wheel    68B Dec 15 21:36 com.apple.corestorage
> drwx------   3 root  wheel   102B Dec 17 22:30 com.apple.coresymbolicationd
> drwxr-xr-x   4 root  wheel   136B Dec 15 21:36 com.apple.kext.caches
> -rw-r--r--@  1 root  wheel    23K Dec 16 21:53
> com.apple.preferencepanes.systemcache
> -rw-r--r--   1 root  wheel    11K Dec 16 09:35
> com.apple.xpc.extensions.cache
> -rw-r--r--   1 root  wheel   203K Dec 16 09:35 com.apple.xpchelper.cache
>
> I’d like to get rid of directories and files except
> com.apple.IntlDataCche.le and com.apple.IntlDataCche.le.kbdx.
>
> And I did;
>
> setopt extendedglob
> rm -rf -^com.apple.IntlDataCache.*
>
> Then I get zsh: no matches found: -^com.apple.IntlDataCache.le.*
>
> Again my system is
>
> sw_vers
> ProductName:    Mac OS X
> ProductVersion: 10.12.2
> BuildVersion:   16C67
>
> Thanks.
>
> AH
>
> > On Dec 25, 2016, at 4:10 PM, Bart Schaefer <schaefer@brasslantern.com>
> wrote:
> >
> > On Dec 25,  7:22pm, Hoji, Akihiko wrote:
> > }
> > } setopt extended glob
> >
> > If you literally did that, you should have gotten an error message; there
> > is no option named "extended" although there is one named "glob".
> >
> > You can use underscores or hyphens between words (actually, between any
> > two letters) in option names, but not spaces.
> >
> > setopt extendedglob
> > setopt extended_glob
> > setopt extended-glob
> > setopt EX_tend-ed_GLOB
> >
> > } rm -rf -^file.ext.*
> >
> > Is there a space missing there between the second "-" and the "^" ?  Or
> > do the files you want to remove really have names beginning with "-" ?
> >
> > } I would appreciate a poster as to what I am doing wrong.
> >
> > Other than misplaced spacing, you seem to have it; see Gabor's example.
>
>

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

* Re: newbie rm --^file question
  2016-12-25 22:47     ` Gabor Maghera
@ 2016-12-25 23:02       ` Akihiko Hohji
  2016-12-27 20:23         ` Roman Neuhauser
  0 siblings, 1 reply; 9+ messages in thread
From: Akihiko Hohji @ 2016-12-25 23:02 UTC (permalink / raw)
  To: Gabor Maghera; +Cc: Bart Schaefer, zsh-users

Got it.  Putting a space between “--“ and “-“  did it.   I really appreciate your explanation of the different usage of  the “--” argument for rm. I though it was specific to zsh like “^”. 

Thanks. 

AH

 
> On Dec 25, 2016, at 5:47 PM, Gabor Maghera <gmaghera@gmail.com> wrote:
> 
> That "--" causes rm to stop looking for flags.  It is handy if the file
> pattern argument supplied to rm includes '-' characters.  See the man page
> for the rm command, it's explained towards the end.
> 
> You don't really need it for what you are doing, but if you would like to
> use it, it is a separate argument from the file or globbing pattern:
> 
> Try:
> 
> rm -rf -- ^com.apple.IntlDataCache.*
> 
> And here is an example where you do need to use the "--" argument:
> 
> ❯ ls
> -o      bar.ext foo     foo.ext
> 
> ~/example/abc
> ❯ rm -o
> rm: illegal option -- o
> usage: rm [-f | -i] [-dPRrvW] file ...
>       unlink file
> 
> ~/example/abc
> ❯ rm -- -o
> 
> ~/example/abc
> ❯ ls
> bar.ext foo     foo.ext
> 
> ~/example/abc
> 
> On Sun, Dec 25, 2016 at 1:49 PM Akihiko Hohji <akhst7@me.com> wrote:
> 
>> Sorry.  Actually extended glob was due to auto-correction by Apple Mail.
>> I really typed in setopt extendedglob.
>> 
>> Either rm -rf with double “-“ ^file.ext.* or a single “-“ does not work.
>> I get the same “no matches found” message.  And there is no space in
>> between “-“.  I’ve gotten this approach with the double “-“ from a post in
>> Stackoverflow.  If I don’t add “*” at the end or begging of file name, it
>> works fine.
>> 
>> To just give you more details, the following is the list of files in
>> /System/Library/Caches;
>> 
>> drwxr-xr-x  16 root  wheel   544B Dec 16 21:53 .
>> drwxr-xr-x  92 root  wheel   3.1K Dec 16 09:31 ..
>> drwxr-xr-x   6 root  wheel   204B Dec 15 21:47 com.apple.CVMS
>> -rw-r--r--   1 root  wheel    42K Oct  4 21:52
>> com.apple.Components2.SystemCache.Components
>> -rw-r--r--   1 root  wheel    57K Sep 13 20:49
>> com.apple.Components2.SystemCache.QuickTimeComponents
>> -rw-r--r--   1 root  wheel   8.6K Dec 16 09:31 com.apple.IntlDataCache.le
>> -rw-r--r--   1 root  wheel    78K Dec 16 09:31
>> com.apple.IntlDataCache.le.kbdx
>> -rw-r--r--   1 root  wheel    21K Dec 16 09:35
>> com.apple.app-sandbox-cache.plist
>> -rw-r--r--   1 root  wheel    41B Dec 16 09:32 com.apple.bootefisignature
>> drwxr-xr-x   3 root  wheel   102B Dec 15 21:36 com.apple.bootstamps
>> drwxr-xr-x   2 root  wheel    68B Dec 15 21:36 com.apple.corestorage
>> drwx------   3 root  wheel   102B Dec 17 22:30 com.apple.coresymbolicationd
>> drwxr-xr-x   4 root  wheel   136B Dec 15 21:36 com.apple.kext.caches
>> -rw-r--r--@  1 root  wheel    23K Dec 16 21:53
>> com.apple.preferencepanes.systemcache
>> -rw-r--r--   1 root  wheel    11K Dec 16 09:35
>> com.apple.xpc.extensions.cache
>> -rw-r--r--   1 root  wheel   203K Dec 16 09:35 com.apple.xpchelper.cache
>> 
>> I’d like to get rid of directories and files except
>> com.apple.IntlDataCche.le and com.apple.IntlDataCche.le.kbdx.
>> 
>> And I did;
>> 
>> setopt extendedglob
>> rm -rf -^com.apple.IntlDataCache.*
>> 
>> Then I get zsh: no matches found: -^com.apple.IntlDataCache.le.*
>> 
>> Again my system is
>> 
>> sw_vers
>> ProductName:    Mac OS X
>> ProductVersion: 10.12.2
>> BuildVersion:   16C67
>> 
>> Thanks.
>> 
>> AH
>> 
>>> On Dec 25, 2016, at 4:10 PM, Bart Schaefer <schaefer@brasslantern.com>
>> wrote:
>>> 
>>> On Dec 25,  7:22pm, Hoji, Akihiko wrote:
>>> }
>>> } setopt extended glob
>>> 
>>> If you literally did that, you should have gotten an error message; there
>>> is no option named "extended" although there is one named "glob".
>>> 
>>> You can use underscores or hyphens between words (actually, between any
>>> two letters) in option names, but not spaces.
>>> 
>>> setopt extendedglob
>>> setopt extended_glob
>>> setopt extended-glob
>>> setopt EX_tend-ed_GLOB
>>> 
>>> } rm -rf -^file.ext.*
>>> 
>>> Is there a space missing there between the second "-" and the "^" ?  Or
>>> do the files you want to remove really have names beginning with "-" ?
>>> 
>>> } I would appreciate a poster as to what I am doing wrong.
>>> 
>>> Other than misplaced spacing, you seem to have it; see Gabor's example.
>> 
>> 


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

* Re: newbie rm --^file question
  2016-12-25 23:02       ` Akihiko Hohji
@ 2016-12-27 20:23         ` Roman Neuhauser
  0 siblings, 0 replies; 9+ messages in thread
From: Roman Neuhauser @ 2016-12-27 20:23 UTC (permalink / raw)
  To: Akihiko Hohji; +Cc: zsh-users

# akhst7@me.com / 2016-12-25 18:02:16 -0500:
> Got it.  Putting a space between “--“ and “-“  did it.   I really
> appreciate your explanation of the different usage of  the “--”
> argument for rm. I though it was specific to zsh like “^”. 

"--" is a POSIX thing.

XCU 12.2 Utility Syntax Guidelines:

Guideline 10:
    The first -- argument that is not an option-argument should be
    accepted as a delimiter indicating the end of options. Any following
    arguments should be treated as operands, even if they begin with the
    '-' character.

(http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html)

XCU 1.4 Utility Description Defaults:

OPTIONS:

  [...]

  Default Behavior: When this section is listed as "None.", it means that
  the implementation need not support any options. Standard utilities that
  do not accept options, but that do accept operands, shall recognize "--"
  as a first argument to be discarded.

  The requirement for recognizing "--" is because conforming applications
  need a way to shield their operands from any arbitrary options that the
  implementation may provide as an extension. For example, if the standard
  utility foo is listed as taking no options, and the application needed
  to give it a pathname with a leading <hyphen-minus>, it could safely do
  it as:

  foo -- -myfile

  and avoid any problems with -m used as an extension.

(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html#tag_17_04)

-- 
roman


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

end of thread, other threads:[~2016-12-27 20:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-25 19:22 newbie rm --^file question Hoji, Akihiko
2016-12-25 20:45 ` Gabor Maghera
2016-12-25 20:49   ` Hoji, Akihiko
2016-12-25 20:51     ` Gabor Maghera
2016-12-25 21:10 ` Bart Schaefer
2016-12-25 21:49   ` Akihiko Hohji
2016-12-25 22:47     ` Gabor Maghera
2016-12-25 23:02       ` Akihiko Hohji
2016-12-27 20:23         ` Roman Neuhauser

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).