[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #56106] make it easier to exclude a directory
From: |
Ernesto Alfonso |
Subject: |
[bug #56106] make it easier to exclude a directory |
Date: |
Tue, 9 Apr 2019 01:13:42 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36 |
URL:
<https://savannah.gnu.org/bugs/?56106>
Summary: make it easier to exclude a directory
Project: findutils
Submitted by: erjoalgo
Submitted on: Tue 09 Apr 2019 05:13:40 AM UTC
Category: None
Severity: 3 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: None
Fixed Release: None
_______________________________________________________
Details:
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
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?56106>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [bug #56106] make it easier to exclude a directory,
Ernesto Alfonso <=