Skip to main content

Count words, lines, characters, or bytes in a file.

# To count the number of words:
wc -w path/to/file

# To count the number of lines:
wc -l path/to/file

# To count the number of bytes:
wc -c path/to/file

# To count files and directories at a given location:
ls -l | wc -l

# If you ever use `wc` in a shell script and need to compare the output with an
# int, you can clean the output (wc returns extra characters around the integer)
# by using xargs:
ls -l | wc -l | xargs