Skip to main content
3 of 3
Add a header for each solution. Clarify: `-b` won't "have" non-printable characters raw, but escape them. Use Python 3 print syntax, which is also valid in Python 2.

ls

Try:

ls -b1A | wc -l

The -b will escape non-printable characters, -A will show all files except . and .., and one per line (the default on a pipe, but good to be explicit).

Python

As long as we're including higher-level scripting languages, here's a one-liner in Python:

python -c 'import os; print(len(os.listdir(os.sep)))'

Or with full 'find':

python -c 'import os; print(len([j for i in os.walk(os.sep) for j in i[1]+i[2]]))'
Arcege
  • 22.9k
  • 5
  • 58
  • 65