I have windows 7 box with cygwin installed. I have multiple folders with files, within a single root folder. I want to find the list of files that have a time stamp within a specific date time range.
3 Answers
You can use the find
command with the -newerXY
option.
From man find
:
-newerXY reference
Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select which time belonging to how reference is used for the comparison.
The possible values for X and Y are as follows:
- a - last access time of current file or reference
- B - birth time of current file or reference
- c - last inode status change time of current file or reference
- m - last modification time of current file or reference
- t - reference is a string representing a timestamp (not valid for X)
X refers to the current file and Y to the reference, so you'll want to use 'm' for the first letter (current file's modification date) and 't' for the second (timestamp passed as a string). Example script:
find . -type f -newermt "2012-05-01" ! -newermt "2012-05-15"
This finds all files that were modified between 1 and 15 May 2012. The !
(logical NOT
) operator reverses the meaning of the argument following it - if -newerXY
means "X is newer than Y", then ! -newerXY
means "X is older than Y".
An alternative option, since you're on Windows, is to use Powershell. The Get-ChildItem
cmdlet returns all files in a given folder (recursively, if desired), and the Where-Object
cmdlet allows you to filter the output of other commands. Example script (assuming the directory you want to search is the current directory):
Get-ChildItem -Recurse | Where-Object { $_.LastWriteTime -ge "2012-05-01" -and $_.LastWriteTime -le "2012-05-15" -and !$_.PSIsContainer }
This returns all files modified between 1 and 15 May 2012. You can use CreationTime
instead of LastWriteTime
to check for file creation time instead. The !$_.PSIsContainer
filter only returns files (PSIsContainer
is true for folders, and the exclamation mark is again the logical NOT
operator).
You can use Far Manager, Find File
with filter:
Hit the filter button, an press Insert
to insert new filter:
Name the filter somehow, enter file mask, check Date/Time
, select value change
, uncheck Relative
and enter the date/time ranges:
Hit ok, and in the Filters menu
, press space
to select the filter (+
should appear next to the filter):
Search results (in this example photos - mask IMG_*.jpg
- date range for June 2022):
It is also possible to find that files with GUI File Explorer. Some examples:
datemodified:2015-02-18 08:00..2015-02-18 13:00
datemodified:>2015-02-18 08:00
datemodified:<2015-02-18 08:00
And some further reading: Advanced tips for searching in Windows, Using Advanced Query Syntax Programmatically
-
We expect high quality answers here at
Superuser
which means answers should include ALL relevant information not just links to external resources.– RamhoundMar 31, 2015 at 11:59 -