1

I know how to find files with suffix .txt in the current directory: find *.txt

How do I invert this?

I am new to Linux, so please help. Thanks!

mklement0
  • 382,024
  • 64
  • 607
  • 775
Big_t boy
  • 299
  • 1
  • 5
  • 18
  • @John1024: You're probably thinking of `find -name '*.txt'`; `find *.txt`, due to using an _unquoted_ glob, will only match `*.txt` files in the _current_ directory (because it is the _shell_ performing the globbing), and pass the matching files as arguments to `find` (hypothetically, if there were `*.txt` _directories_, `find` _would_ recurse into them, listing _all_ files there). – mklement0 Apr 10 '15 at 04:31
  • @mklement0 You are right. – John1024 Apr 10 '15 at 04:32

3 Answers3

2

If you just want the current directory, and your shell is bash:

shopt -s extglob
ls !(*.txt)

reference

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
2

find in current file not recursive

find -maxdepth 1 ! -name "*.txt"
crazier wu
  • 21
  • 4
0
find ! -name  "*.txt"

or

find -not -name "*.txt"
tweej
  • 832
  • 4
  • 16