3
find . -name *.jks -print 2>/dev/null

returns files of extension jks that do not have underscores as part of their name. Much to my surprise, I have just discovered that * does NOT substitute the underscore.

find . -name *_*.jks -print 2>/dev/null

returns files of extension jks that have one underscore.

How do I search for files that have 0 or more underscores? Using OSX Mountain Lion.

4
  • 1
    Is your find supporting and logical operator? find . -name '*.jks' -a ! -name '*_*.jks'
    – manatwork
    Sep 17 '13 at 14:13
  • find . -name '*.jks' -print 2>/dev/null worked. you can submit an answer, @manatwork, and i will go ahead and accept it and up vote
    – amphibient
    Sep 17 '13 at 14:16
  • Your question is a bit strange: in my Linux (CentOS 5), your sample doesn't work. I have to write "*.jks". And, anyway, it returns all files with extension jks, with or without an underscore, that is what you are asking for.
    – AndrewQ
    Sep 17 '13 at 14:16
  • @AndrewQ, probably amphibient has no *.jks file in the work directory itself, so the wildcard is not expanded before the execution of find.
    – manatwork
    Sep 17 '13 at 14:17
11

all versions of find that I know will match underscores with wildcards.

be warned that when doing.

find . -name *.jks -print 2>/dev/null

the "*.jks" might get expanded by the shell, before running the find command.

e.g.

$ mkdir foo
$ touch a.jks foo/a.jks foo/b.jks
a.jks
$ find . -name *.jks -print
./a.jks
./foo/a.jks

this is really because you are actually calling find . -name a.jks -print, and thus it will not find e.g. b.jks.

if you quote the wildcard expression, you might have more luck:

$ find . -name "*.jks" -print
./a.jks
./foo/a.jks
./foo/b.jks

i'm pretty sure that running

$ find . -name "*.jks" -print

will give you all files with and without underscores.

Not the answer you're looking for? Browse other questions tagged or ask your own question.