Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 1 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
add comment

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
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
add comment

Your Answer

 
discard

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.