Search code examples
regexshellunixfindglob

Globbing pattern: exclude a directory


I have the following filepaths

/vol/form/various.txt
/vol/var/sender.py
/vol/var/hello.txt

I would like to get all .txt files that do not have the directory of form in them. For example, something like:

*.txt AND ! */form/*

What would be the correct globbing pattern to do this -- i.e, in a single pattern (or is that not possible)?


Solution

  • Like this:

    find /vol ! -path '*/form/*' -type f -name '*.txt'
    

    If you need to negate a pattern, like with a regex, AFAIK look around are not supported by find -regex*. So it's not possible only with one find regex expression.