Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Compound Glob Specifiers



On Mon, Nov 8, 2021 at 3:03 PM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>
> It would then follow that *(/)/*(/)/somefile would match dir/dir/somefile and not dir/link/somefile.

Lawrence also said this, but since I've already typed it ...

Parenthesized qualifiers can't appear in the middle of a glob.  The
stat() etc. calls that implement the qualifiers are only applied after
the full path name is generated.  Manual in section 14.8.7 says --

  Patterns used for filename generation may end in a list of qualifiers

That means the whole pattern, not individual path segments.  The only
things you can put elsewhere are the flags listed in 14.8.4.

> I want to glob the equivalent of */*/somefile (not **/foo, specifically two directories deep).

If your tree is not excessively deep, you can do it like this (assumes
extendedglob)

% ls **/somefile~*/*/*/*

This says "find all somefile below here, without following symlinks,
and then throw away any names that contain three slashes" (which
includes any that have more than three).

For a tree deep enough to cause **/ to be slow, you have to get
fancier (and this doesn't require extendedglob):

% ls */*/somefile(e^'[[ $REPLY:a = $REPLY:P ]]'^)

The fun thing about that last one is that if you replace "=" with "!="
you can find all the paths that DO have symbolic links.




Messages sorted by: Reverse Date, Date, Thread, Author