1

I used

$ find . -maxdepth 1 \( -path ./.repo -o -path ./out -o -path ./release \) -prune -type d -o -print
.
./external
./anno
./system
./cts
./bionic
./sdk
./abi
./build
./kernel
./hardware
./prebuilts
./MAKE_SUCCESS_FILE
./buildlog
./docs
./prebuilt
./libnativehelper
./bootable
./dalvik
./vendor
./make-export-env
./rawprogram0.xml.bak
./development
./libcore
./device
./frameworks
./pdk
./ndk
./packages
./Makefile
./gdk

to find only folders except .repo out and release in current directory, but the result contains non-folder files, why?

Victor S
  • 4,021
  • 15
  • 43
  • 54

2 Answers2

1

Much of your command doesn't mean what you think it does. In particular, -prune doesn't exclude the identified files, it just prevents them from being descended into (which in your case is already guaranteed by the -maxdepth 1 anyway), and -o means "or" (a short-circuiting Boolean OR), so you're actually applying -print to the files that don't satisfy your test.

I think what you want is this:

find . -maxdepth 1 -not -name .repo -not -name out -not -name release -type d

which prints ., plus all directories in . aside from ./.repo, ./out, and ./release.

ruakh
  • 175,680
  • 26
  • 273
  • 307
0

The things you want to prune come before -prune. How to use '-prune' option of 'find' in sh?

Community
  • 1
  • 1
mike jones
  • 649
  • 4
  • 15