Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
My best effort is: ls -Rlt –  dublintech May 28 '12 at 11:23

1 Answer 1

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.