Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I count the number of words in a directory recursively?

I'm trying to calculate the number of words written in a project. There are a few levels of folders and lots of text files within them.

Can anyone help me find out a quick way to do this?

bash or vim would be good!

Thanks

like image 813
Alistair Colling Avatar asked Feb 22 '16 17:02

Alistair Colling


People also ask

How do you count words in a folder?

Method 1: Check Details in File Folder Then open the file folder and click “More options” button next to “Change your view”. Next click “Details”. Now right click on the header row and choose “More”. In the “Choose Details” dialog box, check “Pages” and “Word count” boxes.

How do I count words in a directory in Linux?

The easiest way to count files in a directory on Linux is to use the “ls” command and pipe it with the “wc -l” command. The “wc” command is used on Linux in order to print the bytes, characters or newlines count.

How can I count all the lines of code in a directory recursively?

There is a little tool called sloccount to count the lines of code in a directory. It should be noted that it does more than you want as it ignores empty lines/comments, groups the results per programming language and calculates some statistics.

How do you use ls recursively?

ls -R : Use the ls command to get recursive directory listing on Linux. find /dir/ -print : Run the find command to see recursive directory listing in Linux. du -a . : Execute the du command to view recursive directory listing on Unix.


1 Answers

use find the scan the dir tree and wc will do the rest

$ find path -type f | xargs wc -w | tail -1

last line gives the totals.

like image 126
karakfa Avatar answered Sep 25 '22 01:09

karakfa