Finding all files with certain extension in Unix?
Solution 1:
find .
only looks in your current directory. If you have permissions to look for files in other directories (root access) then you can use the following to find your file -
find / -type f -name "*.jdk"
If you are getting tons of permission denied messages then you can suppress that by doing
find / -type f -name "*.jdk" 2> /dev/null
Solution 2:
a/
find .
means, "find (starting in the current directory)." If you want to search the whole system, use find /
; to search under /System/Library
, use find /System/Library
, etc.
b/
It's safer to use single quotes around wildcards. If there are no files named *.jdk in the working directory when you run this, then find
will get a command-line of:
find . -name *.jdk
If, however, you happen to have files junk.jdk
and foo.jdk
in the current directory when you run it, find
will instead be started with:
find . -name junk.jdk foo.jdk
… which will (since there are two) confuse it, and cause it to error out. If you then delete foo.jdk
and do the exact same thing again, you'd have
find . -name junk.jdk
…which would never find a file named (e.g.) 1.6.0.jdk
.
What you probably want in this context, is
find /System -name '*.jdk'
…or, you can "escape" the *
as:
find /System -name \*.jdk
Solution 3:
Probably your JDKs are uppercase and/or the version of find
available on OS X doesn't default to -print
if no action is specified; try:
find . -iname "*.jdk" -print
(-iname
is like -name
but performs a case-insensitive match; -print
says to find
to print out the results)
--- EDIT ---
As noted by @Jaypal, obviously find .
... looks only into the current directory (and subdirectories), if you want to search the whole drive you have to specify /
as search path.
Solution 4:
The '.' you are using is the current directory. If you're starting in your home dir, it will probably miss the JDK files.
Worst case search is to start from root
find / -name '*.jdk' -o -name '*.JDK' -print
Otherwise replace '/' with some path you are certain should be parent to you JDK files.
I hope this helps.