0

I would like to ask about how to count the number of files in linux by between two dates and times?

Example I have 10 file like:

Date Modified      Filename
2016101500         1.file
2016101501         2.file
2016101502         3.file
2016101503         4.file
2016101504         5.file

So if I want to count file from time 00.00 to time 03.00, that how many file I have?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sidara KEO
  • 1,693
  • 1
  • 14
  • 34

1 Answers1

1

You can use the find command and specify the time range like this:

find -newerct 2016-10-15T00:00:00 -and -not -newerct 2016-10-15T03:00:01 | wc -l
  • The -newerct allows you to give a literal timestamp that the change time is compared with.
  • The range is build by combining the two times with -and -not.
  • Depending on your use case, you might need to adopt the second string like 2016-10-15T04:00:00.
  • The matching files are piped to wc -l to get the file count.

There are many more useful tests for timestamps, please refer to the documentation of the find command.

Lars Fischer
  • 9,135
  • 3
  • 26
  • 35