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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

testing files based on modified time

Status
Not open for further replies.

jescat

Technical User
Jul 29, 2004
32
US
I would like to spin through a directory and process files older than 1 day old is there a better way to do this other than using the find command.

JesCat
 
You mean other than than
the find -mtime or -atime parameter?

You could check all the date/time stamps
and compare them to the current date/time.
This will be slower than using find,
but would give the ability to say find
files more than 5 minutes old or
less than 20 minutes old, etc. Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
You could adapt the following script

run using: finds /home | tail -10

or

finds /home | grep username | tail -10

Mike

#!/usr/bin/ksh
#
# Script: finds
# Aim: List files in a filesystem by modification time
#
awk="/usr/bin/awk"
basename="/usr/bin/basename"
cut="/usr/bin/cut"
date="/usr/bin/date"
find="/usr/bin/find"
sed="/usr/bin/sed"
sort="/usr/bin/sort"

#
# Functions
#
checkParms()
{
FILELIST=""
for parm in $PARMS
do
if test "$parm" = "-r"
then
REVERSE="r"
else
check=`echo "$parm" | $cut -c1 `
if test "$check" != "-"
then
FILELIST="$FILELIST $parm"
fi
fi
done
return
}

showFiles()
{
(
$date +"%Y %m %d"
$find $FILELIST -xdev -type f -ls
) |
$awk '
NR == 1 {
thisyear = $1
lastyear = $1
thismonth = substr($2+100,2,2)
thisday = substr($3+100,2,2)
}
NR != 1 {
day = substr($9+100,2,2)

if ( $8 == "Jan" ) { month = "01" }
if ( $8 == "Feb" ) { month = "02" }
if ( $8 == "Mar" ) { month = "03" }
if ( $8 == "Apr" ) { month = "04" }
if ( $8 == "May" ) { month = "05" }
if ( $8 == "Jun" ) { month = "06" }
if ( $8 == "Jul" ) { month = "07" }
if ( $8 == "Aug" ) { month = "08" }
if ( $8 == "Sep" ) { month = "09" }
if ( $8 == "Oct" ) { month = "10" }
if ( $8 == "Nov" ) { month = "11" }
if ( $8 == "Dec" ) { month = "12" }

if ( length($10) == 4 )
{
year = $10
hour = "00:00"
}
else
{
if ( month <= thismonth ) { year = thisyear }
if ( month > thismonth ) { year = lastyear }
hour = $10
}
print year &quot;/&quot; month &quot;/&quot; day, hour, $0
}
' |
$sort $REVERSE |
$cut -c17-

return
}

#
# Start of main processing
#
SCRIPT=`$basename $0 `
PARMS=&quot;$*&quot;

showFiles

exit 0
--
| Mike Nixon
| Unix Admin
| ----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top