1
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.
1
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.
2
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:
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).
-1
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. – Ramhound – 2015-03-31T11:59:33.077
Sorry, I just tried to be useful... – mirekbarton – 2015-04-01T19:38:50.727
My best effort is: ls -Rlt – dublintech – 2012-05-28T11:23:03.630