Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the total lines of csv files in a directory on Linux?

Working with huge CSV files for data analytics, we commonly need to know the row count of all csv files located in a particular folder.

But how to do it with just only one command in Linux?

like image 278
Cesar Augusto Nogueira Avatar asked Feb 26 '18 12:02

Cesar Augusto Nogueira


2 Answers

If you want to check the total line of all the .csv files in a directory, you can use find and wc:

 find . -type f -name '*.csv' -exec wc -l {} +
like image 123
Cesar Augusto Nogueira Avatar answered Oct 05 '22 21:10

Cesar Augusto Nogueira


To get lines count for every file recursively you can use Cesar's answer:

$ LANG=C find /tmp/test -type f -name '*.csv' -exec wc -l '{}' +
 49 /tmp/test/sub/3.csv
 22 /tmp/test/1.csv
419 /tmp/test/2.csv
490 total

To get total lines count for all files recursive:

$ LANG=C find /tmp/test -type f -name '*.csv' -exec cat '{}' + | wc -l
490
like image 23
Tns Avatar answered Oct 05 '22 21:10

Tns