0

I have exactly the same problem as this post.

Only instead of finding all the .txt files, I want a list of all files that are not .txt files.

Something like

$ ls -LR | grep -v .java

Which definitely does not do what I want.

2 Answers 2

1

Use find as suggested in that post and negate the -name condition with ! to have the other way round:

find . -type f ! -name "*.txt"
#      ^^^^^^^ ^^^^^^^^^^^^^^^
#   just files        |
#              file names not ending with .txt
3
  • -type f is also required for me in this case, to find only files. I finally looked for not in the find manpage - exclude and inverse aren't present :P Commented Sep 10, 2014 at 14:00
  • Trye! Added -type f. But then, did this solution work to you with !?
    – fedorqui
    Commented Sep 10, 2014 at 14:03
  • 1
    Yes - I just couldn't accept the answer that quickly ;) Commented Sep 10, 2014 at 15:12
0

Does this work for you?,

ls -lr | grep -E -v "*.txt$"  

I tested it on my end and it worked, -E extended grep

1
  • this works only if the r is a capital R ;) (can't edit answers for less than 6 characters)
    – Jerther
    Commented Feb 15, 2017 at 14:26

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