How to limit search result of directories/files to limited top-level directories only?

I did a find / -name 'XXX' and the output is insane. It lists every file and the list never ends (I had to Ctrl-C to stop it).

How can I view the results meaningfully? For example, I'd like to limit to the result to appear only for, say the top-level (or top 2nd or 3rd level) directories only.

For example, find / -name '*hello*' and the result will be very long...
Code:
/home/hello/myfile1
/home/hello/myfile2
/home/hello/myfile3
/usr/local/hello/anotherfile1
/usr/local/hello/anotherfile2
/usr/local/hello/anotherfile3
...
All I need is just a single line for the same directory:
Code:
/home/hello/...
/usr/local/hello/...
(with less information, it is easier to understand and I can zoom into each directory to investigate more).

Any creative suggestions would be appreciated?
 
find <DIR> -name '*hello*' will find everything under <DIR>, including <DIR> itself, with any name matching *hello*.

As an example, suppose you have a few files in /tmp that contains a few files with the name 'hello' in it. Watch what happens with the find command:
Code:
$ find /tmp -name '*hello*'
/tmp/hello
/tmp/hello/hello.go
/tmp/hello/test/hello_test.go
/tmp/hello/hello2.go
/tmp/hello.sh

Based on your explanation, perhaps you seek the functionality provided by -prune. Observe the difference it makes:
Code:
$ find /tmp -name '*hello*' -prune
/tmp/hello
/tmp/hello.sh

/tmp/hello matched *hello*, and /tmp/hello is a directory, so the contents of that directory get skipped. If you had specified find /tmp/hello -name '*hello*' -prune, then it would only output /tmp/hello due to the use of -prune. For more information, see find(1)
 
I just realized that "zfs diff ..." is also giving me the same headache - displaying an endless list of files. What would be the same method/approach?
 
Back
Top