zsh-users
 help / color / mirror / code / Atom feed
* Globbing feature suggestion
@ 2005-12-13  2:07 Jonathan Hankins
  2005-12-13  4:16 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Hankins @ 2005-12-13  2:07 UTC (permalink / raw)
  To: zsh-users

What if you could get the effect of find(1)'s "-nouser" and "-nogroup"
(true for files whose numeric UID and GID have no corresponding entry
in the passwd file) like this:

  print -l *(^u)
  print -l *(^g)

or maybe (to allow 'u' and 'g' clustering)

  print -l *(^u::)
  print -l *(^g::)

The latter would allow you to specify files that had both no user or
group owner.

I sometimes use "find / -nouser -o -nogroup" to locate files owned by
users or groups that have been removed from the system.

Thanks,

-Jonathan Hankins

-- 
+------------------+-----------------------------------------------------+
|Jonathan Hankins  | 		       	 jonathan-hankins@mindspring.com |
+------------------+-----------------------------------------------------+


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

* Re: Globbing feature suggestion
  2005-12-13  2:07 Globbing feature suggestion Jonathan Hankins
@ 2005-12-13  4:16 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2005-12-13  4:16 UTC (permalink / raw)
  To: zsh-users

On Dec 12,  8:07pm, Jonathan Hankins wrote:
}
} What if you could get the effect of find(1)'s "-nouser" and "-nogroup"
} (true for files whose numeric UID and GID have no corresponding entry
} in the passwd file)

This is computationally a fairly expensive operation, particularly if
"the passwd file" is an NIS map or the like.  Zsh's (uID) and (gID)
qualifiers work by looking up the ID once in the appropriate map and
then comparing to the stat data of each file; to implement -nouser or
-nogroup you have to first get the stat data from the file and then
look that up in the map.  You could get into various optimizations
like caching previously-seen IDs so as not to look them up again, but
that's a lot of code for what seems like a fringe feature.

My feeling is that if you're going to invoke something that costly,
you ought to be aware of it; the shell shouldn't hide it behind a two-
letter abbreviation.  It's not obvious, but with "zmodload zsh/stat":

 -nouser is the glob qualifier
 (e['stat -s -A reply +uid $REPLY; reply=(${${(M)reply:#<->}/<->/$REPLY})']) 

 -nogroup is the glob qualifier
 (e['stat -s -A reply +gid $REPLY; reply=(${${(M)reply:#<->}/<->/$REPLY})']) 

You can use the function shorthand in 4.3.x:

 function nouser {
   stat -s -A reply +uid $REPLY
   reply=(${${(M)reply:#<->}/<->/$REPLY})
 }

 print *(+nouser)

Only try that recursively on a deep directory tree, though, when prepared
to wait a while.

Tangentially, a more useful feature would be for (^e:...:) to match the
name when reply=().  Currently (^e:...:) is guaranteed never to match,
and instead you have to figure out how to invert the computation.  If
(^e:...:) were so implemented, then -nouser would be shortened to
 (^e['stat -s -A reply +uid $REPLY; reply=(${reply:#<->})'])
which is not a lot better, but a little.


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

end of thread, other threads:[~2005-12-13  4:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-13  2:07 Globbing feature suggestion Jonathan Hankins
2005-12-13  4:16 ` Bart Schaefer

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