How can I list files having more than 100 lines in a directory and in all its sub directories? An example of such a terminal command will be very helpful.

Is there a tool to count the line numbers of given files?

3 Answers 3


You can count lines with wc, the word count utility:

find . -type f -print0 | xargs -0 wc -l | sort -n
  • Thanks for the edit n the answer. It is working nicely. Would you plz describe the command a bit? May 28, 2013 at 18:51
  • 1
    Sure. The find command prints out all the files in the current directory and its subdirectories. xargs receives that list of files and passes them to a series of wc -l commands, which print the line count of each those files. sort -n sorts the list of files numerically by their line counts. Strictly speaking, it would be more efficient if we could tell wc to stop counting after reaching 100 lines, but I'm not aware of a way to do that.
    – Paul
    May 29, 2013 at 1:07
  • Thanks paul for your kind help. It does nicely, what it exactly suppose to do, but i just want the files that have more than 100 lines and thats where @ortang 's command is more accurate. May 29, 2013 at 10:41

Use the following command:

find <folder-to-search> -name "*.txt" -type f -exec sh -c 'test `wc -l {} | cut -f1 -d" "` -gt "100"' \; -print

Also take a look at the -name parameter, currently you will find only files that end with .txt. You want to alter that or, just delete the parameter and the argument to find all files.


You can do it in one line with awk as well, wanted to add it as a comment to support Paul s answer but due to >> echo "1 reputation" | awk '$1<50' reputation I couldn't :D

find . -type f | xargs wc -l | awk -F "." '$1>100'

Optional --> -name that ortang mentioned with find... and -F is the delimiter, even default space can work like "awk "$1>100"

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.