DEV Community

Alain Mauri
Alain Mauri

Posted on

2 2

Find files between two dates

Find files between two dates

I’d like to share a simple way I’ve learned to find how many files have been created between two dates, using Linux command line. The method involves find command.

Problem

Working on a project that involved the creation of a lot of KOS objects (nothing difficult, just another DICOM object), I needed a quick and easy way to find out how many files my class method created.

Solution

I knew that find command could help, so I started digging into its manual and at the end I found the right option:

 -newerXY reference
Succeeds if timestamp X of the file being considered is newer than timestamp Y of the file reference. The letters X and Y can be any of the following letters:

              a   The access time of the file reference
              B   The birth time of the file reference
              c   The inode status change time of reference
              m   The modification time of the file reference
              t   reference is interpreted directly as a time

after many trials I ended up with newermt which is newer with sub-options X=m for modification date and Y=t for literal time.

At this point my “command” was taking shape:

find -type f -name "*.dcm" -newermt 2016-04-08 ! -newermt 2016-04-09

Last thing I needed to know, was the number of files that have been created in the desired date interval and this was the easiest part of the command:

wc -l

the command used prints the newline count.

Finally:

find -type f -name "*.dcm" -newermt 2016-04-08 ! -newermt 2016-04-09 | wc

Enjoy!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more