2017-09-13 05:11:38 +02:00
|
|
|
# Count the number of words (file or STDIN)
|
|
|
|
wc -w /path/to/foo.txt
|
|
|
|
cat /path/to/foo.txt | wc -w
|
2017-02-13 04:11:45 +01:00
|
|
|
|
2017-09-13 05:11:38 +02:00
|
|
|
# Count the number of lines (file or STDIN)
|
|
|
|
wc -l /path/to/foo.txt
|
|
|
|
cat /path/to/foo.txt | wc -l
|
|
|
|
|
|
|
|
# Count the number of bytes (file or STDIN)
|
|
|
|
wc -c /path/to/foo.txt
|
|
|
|
cat /path/to/foo.txt | wc -c
|
|
|
|
|
|
|
|
# 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
|