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

2

9

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?

Postfix answered 26/2, 2018 at 12:38 Comment(0)
P
10

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 {} +
Postfix answered 26/2, 2018 at 12:38 Comment(1)
Probably just marginal, but keep in mind getconf ARG_MAXExecute
A
5

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
Abroach answered 26/2, 2018 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.