41

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.

59

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.

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