HP-UX find -mmtime results are one day off


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HP-UX find -mmtime results are one day off
# 1  
Old 11-20-2012
HP-UX find -mmtime results are one day off

Hey,

I am writing a script to delete log files that are older than one day (I'm going to run it weekly). Basically, it should work so that it only keeps the current day, but keeping the previous day as well isn't a dealbreaker.

I am running the following line on the files listed below:

Code:
find ./rpt*.log -mtime +1

Code:
-rw-r--r-- 1 user usergroup 19195074 Nov 15 23:53 rpt.1115.log
-rw-r--r-- 1 user usergroup 17083282 Nov 16 23:46 rpt.1116.log
-rw-r--r-- 1 user usergroup 9561236 Nov 17 23:59 rpt.1117.log
-rw-r--r-- 1 user usergroup 9252635 Nov 18 23:56 rpt.1118.log
-rw-r--r-- 1 user usergroup 16840981 Nov 19 23:58 rpt.1119.log
-rw-r--r-- 1 user usergroup 11956072 Nov 20 15:05 rpt.1120.log

Assuming that I run the script at 16:00 on Nov 20, I would expect that it would return each of the above files except for the 19th and 20th. However, here are the results:

Code:
./rpt.1115.log
./rpt.1116.log
./rpt.1117.log

Could someone explain to me the results here, and why it's not returning the file modified at 23:58 on 11/18 as well?

Thanks.
# 2  
Old 11-20-2012
It's not returning the 11/28 file because find's calculation discards remainders. From the POSIX find manual:
Quote:
-mtime n
The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n.
If find runs at 11/20 16:00, that file's mtime, 11/18 23:58, is about 1.66 days old (40 hours old) . Truncating the 1.66 result to 1 does not satisfy the condition you've specified -mtime +1, for which a true result requires a value greater than or equal to 2.

Use ! -mtime -1.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Weird 'find' results

Hello and thanks in advance for any help anyone can offer me I'm trying to learn the find command and thought I was understanding it... Apparently I was wrong. I was doing compound searches and I started getting weird results with the -size test. I was trying to do a search on a 1G file owned by... (14 Replies)
Discussion started by: bodisha
14 Replies

2. UNIX for Dummies Questions & Answers

How to do ls -l on results of grep and find?

Hi, Am running the command below to search for files that contains a certain string. grep -il "shutdown" `find . -type f -mtime -1 -print` | grep "^./scripts/active" How do I get it to do a ls -l on the list of files? I tried doing ls -l `grep -il "shutdown" `find . -type f -mtime -1... (5 Replies)
Discussion started by: newbie_01
5 Replies

3. UNIX for Dummies Questions & Answers

sort find results

Hi, I have a problem with a shell script. The script should find all .cpp and .h files and list them. With: for file in `find $src -name '*.h' -o -name '*.cpp' it gives out this: H:\FileList\A\E\F\G\newCppFile.cpp H:\FileList\header01.h H:\FileList\B\nextCppFile.cpp ... (4 Replies)
Discussion started by: shellBeginner75
4 Replies

4. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

5. Solaris

Piping results of 'ls' to 'find' using 'xargs'

I'm trying to get a count of all the files in a series of directories on a per directory basis. Directory structure is like (but with many more files): /dir1/subdir1/file1.txt /dir1/subdir1/file2.txt /dir1/subdir2/file1.txt /dir1/subdir2/file2.txt /dir2/subdir1/file1.txt... (4 Replies)
Discussion started by: MartynAbbott
4 Replies

6. Shell Programming and Scripting

need to move find results

I am looking for files of a certian type and logging them. After they are logged they need to be moved to a different directory. HOw can i incorporate that in my current script? CSV_OUTFILE="somefile.csv" find . -name W\* -exec printf "%s,%s,OK" {} `date '+%Y%m%d%H%M%S'` \; > ${CSV_OUTFILE} ... (9 Replies)
Discussion started by: pimentelgg
9 Replies

7. Shell Programming and Scripting

edit results of a find command

Hi Purpose is to have a utility command to find and edit files . I tried a function like the following in my .profile file function vifind(){ find . -name $1 -print -exec vi {} \; } Is this correct? is there a better way to do it? I see this behaving a bit strange in case of AIX, and... (6 Replies)
Discussion started by: grep_whoami
6 Replies

8. UNIX for Dummies Questions & Answers

How to sort find results

Hi-- Ok. I have now found that: find -x -ls will do what I need as far as finding all files on a particular volume. Now I need to sort the results by the file's modification date/time. Is there a way to do that? Also, I notice that for many files, whereas the man for find says ls is... (8 Replies)
Discussion started by: groundlevel
8 Replies

9. UNIX for Dummies Questions & Answers

find results

Hi, how can I get only useful results from find / -size 10000000 without the "Permissions denied" files ? tks C (5 Replies)
Discussion started by: Carmen123
5 Replies

10. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question