0

how can I search for the number of txt Files in my Folder. i tried many things but nothing works.

ls -1 *txt gave the list of txt's but i Need the number!

I also tried some combinations but that didnt work also. ls-1 *txt | wc -1

hopefully you can help me thank you.

Flimzy
  • 68,325
  • 15
  • 126
  • 165
classic
  • 37
  • 7
  • Please avoid *"Give me the codez"* questions that have been asked and answered so many times you have to make an effort to avoid finding an answer. Also see [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/608639) – jww Jul 06 '18 at 09:27

2 Answers2

1

In your command, you do wc -1 it's not correct. you change letter 1 by l and it will work

i hope that help you

Ahmed
  • 185
  • 8
0

some ways of doing this task:

recursively

  1. find . | grep -c '\.txt$'
    1.1 . is for current working directory and all sub-direcotores
    2.1 -c is for counting

  2. find . -name \*.txt | wc -l
    2.1 -name is for matching
    2.2 -l is for counting

non-recursively

  1. ls -1 *.txt | wc -l
  2. perl -le '++$n for <*.txt>; END{ print $n }'
    2.1 increase $n for each *.txt and print it at the END
Shakiba Moshiri
  • 16,284
  • 2
  • 23
  • 38