Skip to main content
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.
Source Link

ls

Try:

ls -b1A | wc -l

The -b will haveescape 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]]))'

Try:

ls -b1A | wc -l

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

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]])'

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]]))'
Add solution in Python
Source Link
Arcege
  • 22.9k
  • 5
  • 58
  • 65

Try:

ls -b1A | wc -l

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

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]])'

Try:

ls -b1A | wc -l

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

Try:

ls -b1A | wc -l

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

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]])'
Source Link
Arcege
  • 22.9k
  • 5
  • 58
  • 65

Try:

ls -b1A | wc -l

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