Operating System - HP-UX
1833017 Members
2450 Online
110048 Solutions
New Discussion

find command - file modification date

 
Renetta Brown_1
Occasional Advisor

find command - file modification date

I'm trying to find and list files (eventually remove them) that have a modification/creation date of previous day. I'm trying
find /u01/app/oasist/pbin/*.log -mtime -1 -exec ls -la {} \;
but it's giving me a listing of files from today and yesterday.
18 REPLIES 18
DIPAK KUMAR ROY
Frequent Advisor

Re: find command - file modification date

find /u01/app/oasist/pbin/*.log -mtime +1 -exec ls -la {} \;


Thanks
Renetta Brown_1
Occasional Advisor

Re: find command - file modification date

Thanks, but that doesn't list the files from yesterday either, but, it does exclude those from today and yesterday. (lists 1 that I have from April of 2002)

maic_dev2:/u01/app/oasist/pbin> find /u01/app/oasist/pbin/*.log -mtime +5 -exec ls -la {} \;
-rwxr-xr-x 1 oasis dba 0 Apr 11 2002 /u01/app/oasist/pbin/bill_eng.log

I'd like to only get/remove the file from yesterday, December 16th.

-rw------- 1 root sys 15092 Dec 16 20:23 /u01/app/oasist/pbin/12_16_103.log
-rw-r--r-- 1 oasis dba 875 Dec 17 10:19 /u01/app/oasist/pbin/12_17_103.log
DIPAK KUMAR ROY
Frequent Advisor

Re: find command - file modification date

Please check your command. You typed it wrong. ( +5 instead of +1)

Thanks
RAC_1
Honored Contributor

Re: find command - file modification date

Whay find?

ll -ct|grep -i "Dec 16"
There is no substitute to HARDWORK
Renetta Brown_1
Occasional Advisor

Re: find command - file modification date

Same result with +5 or +1:
maic_dev2:/u01/app/oasist/pbin> find /u01/app/oasist/pbin/*.log -mtime +1 -exec ls -la {} \;
-rwxr-xr-x 1 oasis dba 0 Apr 11 2002

maic_dev2:/u01/app/oasist/pbin> find /u01/app/oasist/pbin/*.log -mtime +5 -exec ls -la {} \;
-rwxr-xr-x 1 oasis dba 0 Apr 11 2002 /u01/app/oasist/pbin/bill_eng.log
Pete Randall
Outstanding Contributor

Re: find command - file modification date

You could always use grep to search for the specific date. You could also use the touch command to create reference file(s) with the correct time(s) and the "-newer" option of find to locate files that fall between those correct times.


Pete

Pete
john korterman
Honored Contributor

Re: find command - file modification date

Hi,
how about this:

# find /u01/app/oasist/pbin/*.log -type f \( -mtime +0 -a -mtime -2 \) -exec ls -ltr {} \;

regards,
John K.


it would be nice if you always got a second chance
Renetta Brown_1
Occasional Advisor

Re: find command - file modification date

I want the process automated, so, I don't want to supply date every time. (or have to code something to supply it)
Renetta Brown_1
Occasional Advisor

Re: find command - file modification date

Thanks, but this one didn't retrive anything...
maic_dev2:/u01/app/oasist/pbin> find /u01/app/oasist/pbin/*.log -type f \( -mtime +0 -a -mtime -2 \) -exec ls -ltr {} \;
maic_dev2:/u01/app/oasist/pbin>


RAC_1
Honored Contributor

Re: find command - file modification date


export YESTERDAY=$(TZ=$(date +%Z)+24; date '+%b %e')

ll|grep -i ${YESTERDAY}

There is no substitute to HARDWORK
Renetta Brown_1
Occasional Advisor

Re: find command - file modification date

???

maic_dev2:/u01/app/oasist/pbin> ll|grep -i ${YESTERDAY}
grep: can't open 16
RAC_1
Honored Contributor

Re: find command - file modification date

export YESTERDAY=$(TZ=$(date +%Z)+24; date '+%b %e')

ll|grep -i "${YESTERDAY}"

note double quotes
There is no substitute to HARDWORK
Renetta Brown_1
Occasional Advisor

Re: find command - file modification date

Success! Thanks!
Helen French
Honored Contributor

Re: find command - file modification date

Here you go:

# find /u01/app/oasist/pbin/*log -mtime 1 -exec ls -al {} \;

Note the "1" and not +1 or -1. This what each one of it will do:

1 - between 24 and 48 hours old
+1 - 48 hours or older
-1 - within 24 hours

Please remember that -mtime calculates times in 24 hours and not in actual *days* as we calculate.
Life is a promise, fulfill it!
Renetta Brown_1
Occasional Advisor

Re: find command - file modification date

Thanks for that info...
Dave La Mar
Honored Contributor

Re: find command - file modification date

Renetta -
This is the find command I use for a daily cleanup of one of out /tmp directories.

find /tmp/ -type f -mtime -1 > output_file

This is for all files within the last 24 hours.
To eliminate today's:

grep -v "date '+%b %m'" output_file > delete_file

Of course your cript will have to sed or cut the file name field.

Best of luck.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Dan_242
Occasional Advisor

Re: find command - file modification date

Great! Is there a way to list it the long way? Like this :

-rw-r--r-- 1 rahxgb users 3552 Apr 4 2000 mailqmon.log



Dan_242
Occasional Advisor

Re: find command - file modification date

Sorry, I don't think that questions was very clear. What I ment to ask was if there was a way write to output_file that would list the the long format as in "ls -al"...

- Dan