Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
Thanks !!!!!!!! – 22lk94k943 only May 29 '13 at 10:41
You are welcome – ortang May 29 '13 at 11:07

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

find . -type f -print0 | xargs -0 wc -l | sort -n
share|improve this answer
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
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 posting your answer, you agree to the privacy policy and terms of service.

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