Ubuntu – List files having more than 100 lines in a directory and in all it’s sub directory

command linefiles

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?

Best Answer

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.