Suppose running ls
command gives the following output on terminal:
1.txt 2.txt 3.txt '4 b'
['4 b' is the name of a folder]
When I run ls | wc -c
at the same location, I get 18, which is because it considers space as a character. What should I do to avoid counting spaces as characters(even the spaces within the filenames)?
CodePudding user response:
You could delete all spaces:
ls | tr -d ' ' | wc -c
CodePudding user response:
You can use tr
to remove the spaces:
ls | tr -d ' ' | wc -c