Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

hadoop - How to count number of files groupped by date in hdfs

How could we count files from a hdfs folder, groupped by date?

Example:
2020-01-03 10:00:00 - file 1
2020-01-03 11:00:00 - file 2
2020-01-03 12:00:00 - file 3
2020-02-03 10:00:00 - file 4

Expected result:
3 2020-01-03
1 2020-02-03
question from:https://stackoverflow.com/questions/65923492/how-to-count-number-of-files-groupped-by-date-in-hdfs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do it with the below command. The stat "%y" command helps you get the modification date and cut -d' ' -f1|sort|uniq -c will cut the date, sort it and count the unique values.

hdfs dfs -stat "%y" path | cut -d' ' -f1|sort|uniq -c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...