bugfindutils - Bugs: bug #56106, make it easier to exclude a...

 
 

bug #56106: make it easier to exclude a directory

Submitter:  Ernesto Alfonso <erjoalgo>
Submitted:  Tue 09 Apr 2019 05:13:40 AM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  None Status:  Works For Me
Privacy:  Public Assigned to:  berny
Originator Name:  Open/Closed:  Closed
Release:  None Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 18 Jun 2019 08:07:05 PM UTC, comment #2: 

Without further comments on this in two month, I'm hereby closing this issue (still as 'works-for-me').

Bernhard Voelker <berny>
Group administrator
Tue 09 Apr 2019 05:55:23 AM UTC, comment #1: 

Wow, what a stackoverflow thread!  I didn't read through it much
as the proposed commands seem to address some other aspects as well.

Your examples often use -path (alias -wholename) while I think you
wanted -name.

> The expected behavior would be to exclude everything matching a
> given prefix or directory, including the directory itself, from
> the set of files or directories that would normally be returned
> without the added predicate.


What about the following (which is documented both in the man page
and the texinfo documentation)?


$ find . -name .git -prune -o -print


As some users already seem to be overwhelmed with the complexity
and possibilities of find(1) predicates, adding yet another probably
conflicting way would be even more confusing.
Finally, the above works quite nice, so I don't see a need.
Therefore, I'm marking this as "works for me".

Have a nice day,
Berny

Bernhard Voelker <berny>
Group administrator
Tue 09 Apr 2019 05:13:40 AM UTC, original submission:  

The current ways of excluding a directory in find are confusing or have shortcomings that make them hard to use, and there seems to be no simple, intuitive, easy to remember way to do this.

Several ways of doing this have been proposed in this stackoverflow question[1]:

The first one suggests using "-path ./DIRECTORY -prune". When I used tried to use this approach to exclude a .git directory and its contents:

1. I first got an unexpected result:

    $ find . -path .git -prune
    # nothing matches

2. Then I tried adding a leading "./" to the -path, which gave me a single result, .git, the same directory I am trying to exclude:

    $ find . -path ./.git -prune
    ./.git


3. Then I tried adding a "-o -type f" condition:

    $ find . -path ./.git -prune -o -type f

This includes only regular files, so it's not the same as simply "excluding a directory", since I have to explicitly say what I want to include. It also seems to still include the './.git' directory I wanted to exclude

I looked into the next answer, which relies on passing a shell-escaped glob star:

    $ find -not -path "./.git/*"

This seems better than #3, since it is closer to "find everything except ..." without having to specify what to include. The problem with this is that it hard to build on top of find in shell scripts using this glob approach without running into many types of shell escaping issues. This also still includes "./.git" itself.

The next answer suggests that it is easier to reason about this form:

5. find build -not \( -path build/external -prune \) -name \*.js

I find this double negation confusing and don't see anything intuitive about it, and it involves a complicated explanation about how -prune and -not work together.

Could we have a simpler, script-friendly way of excluding a directory tree that is more intuitive to remember and understand?

Perhaps something like:

    $ find . -not -prefix .git
    # maybe this should also work
    $ find . -not -prefix ./.git

The expected behavior would be to exclude everything matching a given prefix or directory, including the directory itself, from the set of files or directories that would normally be returned without the added predicate.

Or is there already an intuitive way of doing this that is free from some of the shortcomings I mentioned above?

[1] https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command

Ernesto Alfonso <erjoalgo>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by berny (Posted a comment)
  • -email is unavailable- added by erjoalgo (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-06-18 berny Open/ClosedOpen Closed
    2019-04-09 berny CategoryNone find
        StatusNone Works For Me
        Assigned toNone berny

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code