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?


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 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? – 22lk94k943 only May 28 '13 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 '13 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. – 22lk94k943 only May 29 '13 at 10:41

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.