66

Let say I have:

foo.txt
bar
baz.ooo

If I use ls -1 !(*.*) then I'll get only bar on the output. Great, now I wish to have same results with find - some find -regex that will do the job.

NOTE:

find -name !(*.*) is not the answer as !(*.*) in it is still Bash's glob which I can NOT use.

1 Answer 1

95

you could use: find . -type f ! -name "*.*" the ! negates the following expression, here a filename that contains a '.'

you can also use the -maxdepth option to reduce the search depth.

4
  • 1
    I like your answer the most as mine has some other constrains for the filenames and yours is bullet proof.
    – pawel7318
    Jul 12, 2014 at 18:55
  • This is also great when ls -1 !(*.*) won't work because the ! gives "Event not found."
    – Noumenon
    Oct 15, 2016 at 15:12
  • 2
    @Noumenon do set +H to solve that
    – pawel7318
    Jun 7, 2018 at 14:15
  • 5
    If you treat .gitignore as a file without extension (like Node's path.extname()), use ! -name "?*.*" instead of ! -name "*.*" Sep 21, 2018 at 8:14

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.