0

I want to find all files with the name java in folders containing /current/jre/bin/ and without the many permission denied errors.

So I thought find / -type d '*/current/jre/bin/*' 2>/dev/null should do the job. But the return is nothing. I also tried it without the *, with -wholename (with and without *), with an additional -name, -name but without -type d and some other commands.

If I instead search for the java files with find / -name 'java' 2>/dev/null I receive eleven path, from which I only need three.

2 Answers2

0

Putting the '*/current/jre/bin/*' after -type d confuses find so it cannot determine which path you want to search. If you removed the 2>/dev/null you would see the error find: paths must precede expression.

Instead, use a pipe to grep:

find / -name 'java' 2>/dev/null | grep '/current/jre/bin/'
DavidH
  • 415
  • 4
  • 21
0

The proper way to say "the path must contain this" is with -path

find / -type d -path '*/current/jre/bin/*' 2>/dev/null

Specifying a bare string in the predicates is an error, which you would easily have found out if you didn't redirect error messages to /dev/null. Even then, having the command return immediately even though you are scanning the entire file tree should be a dead giveaway.

Pro tip: also add -xdev to the options, to avoid having find going into /dev and etc. If you have your files split on multiple partitions, you will then need to specify each partition you want to search in the path list before the predicates.

(The general syntax is find path1 path2 path3 ... -list -of -predicates.)

tripleee
  • 175,061
  • 34
  • 275
  • 318