Cesar Augusto Nogueira
Cesar Augusto Nogueira

Reputation: 2221

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?

Upvotes: 9

Views: 4369

Answers (2)

Tns
Tns

Reputation: 410

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

Upvotes: 5

Cesar Augusto Nogueira
Cesar Augusto Nogueira

Reputation: 2221

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 {} +

Upvotes: 10

Related Questions