Putting aside that there would be issues with file names that contain newlines, there are a couple of efficiency improvements I can think of:
- Pass the
$PWD
directly to find, instead of determining it for each sub-shell. This will make find
include the full path in its output.
- Cut parent directory names off with
rev
and cut
.
So I would suggest the following to get a list of all directories containing the desired file:
find "$PWD" -name '__openerp__.py' |
rev |
cut -d/ -f3- |
rev
Note that find
does not order its output, so it should be sorted before uniq'ing it. As sort
already supports squeezing identical elements (-u switch), the original question can then be answered with:
find "$PWD" -name '__openerp__.py' |
rev |
cut -d/ -f3- |
rev |
sort -u