OS Commands:- Find Files Processed In the Last N Days

Background

I need to find files that I have worked on lately.

 

OS

OS  Linux

Find Command

Samples

Sample – Find Files modified In the Last 3 Days
Outline
  1. Folder
    • Folder is .
      • . here means current folder
  2. Type
    • Type is f
      • Type is f as in file
  3. iname
    • iname means case insensitive name
      • iname is *.sql
  4. mtime
    • mtime means modification time
      • mtime  -N ( -3 ) means modified in the last N ( 3 ) days
Code

find . -type f -iname *.sql -mtime -3

 

MS Windows ( MS DOS )

Find Command

The Find command does not have an option that considers date.

ForFiles Command

Samples

Sample – Find Files Touched Since Specific Date
Outline
  1. /P
    • Path is .
      • . here means current folder
  2. Sub Folder
    • /S
      • Include sub-folder
  3. File Mask
    • /M stands for file mask
      • .M is *.sql
  4. /D
    • /D is file’s modification time
      • +06/07//2022 means file’s modified since 2022-June-6th
      • 06/07//2022 means file’s modified prior to 2022-June-6th
Code

forfiles /P . /S /M *.sql /D +06/07/2022

Explanation
  1. Output Format
    • “Bare” File Names returned
    • Folder Structure is not returned
Sample – Find Files Touched Prior To Number of Days
Outline
  1. /P
    • Path is .
      • . here means current folder
  2. Sub Folder
    • /S
      • Include sub-folder
  3. File Mask
    • /M stands for file mask
      • .M is *.sql
  4. /D
    • /D is file’s modification time
      • -3 means file’s modified prior to 3 days ago
Code

forfiles /P . /S /M *.sql /D -3

Sample – Find Files Touched Post N Days
Outline
  1. /P
    • Path is .
      • . here means current folder
  2. Sub Folder
    • /S
      • Include sub-folder
  3. File Mask
    • /M stands for file mask
      • .M is *.sql
  4. /D
    • /D is file’s modification time
      • +0 means file’s modified since the the beginning of the current day
Code

forfiles /P . /S /M *.sql /D +0

Summary

Unfortunately, the Microsoft’s implementation has significant short comings.

Find

  1. Does not have a date argument

ForFiles

  1. Absolute Dates
    • Supports absolute date
      • To flag prior files, precede absolute date with minus sign ( )
      • To flag successive files, precede absolute date with minus sign ( + )
  2.  Relative
    • Supports tagging files pre N days
    • Does not support tagging files post N days
      • Except when N is zero ( 0 ) days
        • For Today, you will pass in 0

References

  1. ForFiles

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s