CyberKeeda In Social Media

Linux - Count no of files in a folder by day.

 


One Liner to count the number of files in a directory by date.

We often got this requirement where we have to deal with file counts, we have a huge list of files within a folder and we want to count the number of files created by date.

One Liner Linux CLI command

# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

 
Output for above command will look something like below.

1 2019-07-03 1 2019-08-08 6 2019-08-13 1 2019-08-15 1 2019-09-10 2 2019-09-11 1 2019-09-23 1 2019-10-22 1 2019-10-25 1 2019-10-29 1 2019-12-05 1 2020-03-04 2 2020-03-30 1 2020-04-07 11 2020-04-08 2 2020-04-09 1 2020-04-21 1 2020-04-26 2 2020-04-30 430 2020-05-06 1 2020-05-20 4 2020-05-26 951 2020-07-01 434 2020-07-02 1 2020-07-05 2 2020-07-06 100 2020-07-15 1 2020-07-28 6 2020-07-29 1 2020-08-01 2 2020-09-03


Let's break out the command and understand one by one highlighted in pale Yellow.

find . -type f

# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

Find . -type f 

Find command will fetch only the files ( -type f ) within present directory ( . )


-printf '%TY-%Tm-%Td\n'

# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

-printf '%TY-%Tm-%Td\n' will prints the modification time of files in e.g. 2020-04-26 format

sort | uniq -c
# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

sort : It will sorts the output 
uniq -c : It will count the sorted output by date.


Feel free to use it,  thank me later ;)

No comments:

Post a Comment

Designed By Jackuna