75

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

109

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
    Commented Jul 12, 2014 at 18:55
  • 1
    This is also great when ls -1 !(*.*) won't work because the ! gives "Event not found."
    – Noumenon
    Commented Oct 15, 2016 at 15:12
  • 3
    @Noumenon do set +H to solve that
    – pawel7318
    Commented Jun 7, 2018 at 14:15
  • 6
    If you treat .gitignore as a file without extension (like Node's path.extname()), use ! -name "?*.*" instead of ! -name "*.*" Commented Sep 21, 2018 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .