Hi all,
i have a simple question that i want to find out the 30 minutes older files and delete those files from the particular location(Folder)
Generally for this purpose used to retreive the files with "atime" command
For example: find and delete the 2 days older log files use this below command
find $HOME/Log -type f -name "*.log" -atime+2 -exec {} \;
But how can use for 30 min older files...?
Suggession are apprciated.
Thanks and Regards,
MPS
Use *min for minutes.
find $HOME/Log -type f -name "*.log" -amin +30 -exec ls {} \;
If the OP is on Linux or has GNU find -amin works
Otherwise try:
#!/bin/ksh
# filetimes
filetime()
{
perl -e '
$mtime = (stat $ARGV[0])[9];
print $mtime
' $1
}
now=$(date +%s)
limit=$(( $now - 1800 )) # one half hour ago.
find /path/to/files -type f |\
while read filename
do
dt=$(filetime $filename)
if [[ $dt -lt $limit ]] ; then
rm -f $filename # delete ALL files older then 30 minutes
fi
done