Skip to main content
added 110 characters in body
Source Link
codeforester
  • 816
  • 2
  • 10
  • 23

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:

find -maxdepth 1 -type f -print0 | tr -cd '\0' | wc -c

This saves us from the ordeal of parsing ls output.


Related:

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:

find -maxdepth 1 -type f -print0 | tr -cd '\0' | wc -c

Related:

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:

find -maxdepth 1 -type f -print0 | tr -cd '\0' | wc -c

This saves us from the ordeal of parsing ls output.


Related:

deleted 149 characters in body
Source Link
codeforester
  • 816
  • 2
  • 10
  • 23

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:

find -maxdepth 1 -type f -print0 | wctr --files0-from=-cd '\0' | wc -lc
 

From man wcRelated:

--files0-from=F

read input from the files specified by NUL-terminated names in file F;
If F is -  then  read  names  from standard input

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:

find -maxdepth 1 -type f -print0 | wc --files0-from=- -l

From man wc:

--files0-from=F

read input from the files specified by NUL-terminated names in file F;
If F is -  then  read  names  from standard input

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:

find -maxdepth 1 -type f -print0 | tr -cd '\0' | wc -c
 

Related:

Post Undeleted by codeforester
Post Deleted by codeforester
Source Link
codeforester
  • 816
  • 2
  • 10
  • 23

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:

find -maxdepth 1 -type f -print0 | wc --files0-from=- -l

From man wc:

--files0-from=F

read input from the files specified by NUL-terminated names in file F;
If F is -  then  read  names  from standard input