Ubuntu – How to count number of files in a directory but not recursively

command line

Simple question I'm sure. I've seen an answer that show how to do it including subdirectories, but I want to know how many files (not folders) are in the current directory only. Thanks.

Best Answer

ls -F |grep -v / | wc -l
  1. ls -F list all files and append indicator (one of */=>@|) to entries
  2. grep -v / keep all de strings that do not contain a slash
  3. wc -l count lines