I would like to run the command find . '! -name *.*' in the bash shell. It does not work as intended. (It should list all files in the current directory for which -name *.* is false, i.e. which do not have a dot in their names.) Instead, it prints a list of all files in the directory and, paradoxically, ends with the line find: "! -name *.*": file or directory not found. I suspect the problem is interpretation of the expression by the shell, although it is protected by the two apostrophe (U+0027) characters. Are there ways to protect the expression reliably whatever the expression is?

I use this version: find (GNU findutils) 4.4.2


Due to the OP quoting the expr '! -name *.*' it turns into the 2nd argument to find. So now what find thinks is that you passed to it 2 directory names, viz., . and a crazy name ! -name *.*, so it'll faithfully try to list out all files/subdirs recursively in these two. With . so far so good, but when the time comes to dive into that crazy dir. ! -name *.* it can't, unless you have it. And even then, find won't be doing what you wanted.

For that you have to quote at the proper places:

find . ! -name '*.*'


eval find . '! -name "*.*"'

Try putting the single quotes around the expression only.

find . ! -name '*.*'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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