How to un-select files in shell wildcard patterns

Polytropon freebsd at edvax.de
Fri Jun 21 05:59:13 UTC 2019


On Fri, 21 Jun 2019 14:09:53 +1000, andrew clarke wrote:
> On Fri 2019-06-21 05:49:09 UTC+0200, Polytropon (freebsd at edvax.de) wrote:
> 
> > I'm interested in a convenient method to "un-select" files
> > when using regular (sh) shell wildcards. It's quite easy to
> > describe things like
> > 
> > 	*.tex
> > 
> > to perform an operation on all LaTeX source files, or
> > 
> > 	*a*
> > 
> > on all files whose name contains (at least) one "a". Patterns
> > that are based on the inclusion of certain attributes are not
> > a problem to deal with using the builtin pattern matching of
> > the shell.
> > 
> > But what about the opposite? Let's say, perform an operation
> > on all files _except_ the LaTeX source files, or all files
> > whose name does _not_ contain an "a"?
> > 
> > Is there a good method to do this, except creating a kind
> > of "custom regex wrapper script" that does the selection part,
> > for further use with `subshell` or | xargs?
> 
> zsh can do glob exclusion once "extended globbing" is enabled:
> 
> $ setopt extendedglob
> 
> List all files except LaTeX source files:
> 
> $ ls ^*.tex
> 
> List all files except those with an 'a' character in the name:
> 
> $ ls ^*a*

Again, zsh shows its superiority, but the solution should
work in regular sh (primarily for portability) and maybe
in csh (for convenience). ;-)




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list