Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file date check 1

Status
Not open for further replies.

dwcasey

MIS
Oct 31, 2002
179
0
0
US
I am wanting to check the date of all files in a directory and if they are not today's date, send an alert ( email, log, etc. )

If I run:

find . -type f -mtime +1

in my directory where the files are, I get files that are 1 day old. This will work, but I was just wondering if there was a more 'elegant' way to do this?
 
I don't know if it's more elegant or not, but a common method for finding files created just today is to create a file at midnight, and use find's -newer option:

# untested
Code:
touch -t 200810150000 /tmp/neweroptionfile
find . -type f -newer /tmp/neweroptionfile -print

The above find command returns only files with a modification time after midnight on 10/15/2008. You can use the same method to find files modified within a given date range:

# untested
# find files modified in the first quarter of 2008
Code:
touch -t 200801010000 /tmp/newerstart
touch -t 200803312359 /tmp/newerend

find . \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -print
 
Believe "touch -t" is only in Linux or equivalent.

If you don't have that, one could just parse an ls long listing for the date time stamp since a recent file does not have the year explictly, and all that don't conform must be from a previous 'day'.
 
touch -t is pretty widely available (Solaris, AIX, HP-UX, ...).

Annihilannic.
 
Checked around, Anni is right on. Guess I was thinking like old 4.3 BSD touch.

Cool.
 
olded - here's a star for teaching me touch -t! Thank you

Find has always worked well for something like this, unless you need to find something in a specific subdirectory and don't want it to transcend directories. Then it's usually been easier to grep stuff out of ls...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top