It could be with anything: terminal, Vim, Atom. How to count the total number of words from all the files in a directory?

1

3 Answers

If you just want the total number of words in all the files in a directory (and assuming no sub directories, ignoring hidden files and other caveats), you could try:

cat * | wc -w 

cat * simply concatenates the content of all the files in the current directory to standard output. This is piped into wc -w wc (word count) simply returns the number of words that (in this case) it reads from standard input.

If you're ok with slightly more complex output, simply try:

wc -w * 

wc has other options that return number or lines, number of characters etc.

You can use

find . -type f -exec wc -w {} + | tail -n1 

Sample output:

 % find . -type f -exec wc -w {} + | tail -n1 8704 total 

Tested on Debian Buster (10.5) with

 % find --version find (GNU findutils) 4.6.0.225-235f 
find . -maxdepth 1 -type f -exec wc -w {} \; 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy