Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Command Question

2 views
Skip to first unread message

ame...@iwc.net

unread,
Dec 4, 2006, 4:07:29 PM12/4/06
to
Hey All,

I saw this command in our cron. Was wondering what it really does. I
get lost after the part that looks in /export/home/oracle for files
starting with the date........

/bin/find /export/home/oracle -name `date +\%Y`\*.* -a -mtime +20 -a !
-type d -exec rm -f {} \;

Thanks!

Todd H.

unread,
Dec 4, 2006, 8:58:22 PM12/4/06
to
"ame...@iwc.net" <ame...@iwc.net> writes:

It looks for stuff in that oracle subdirectory that:
o with the name beginning with the current 4 digit year (date
+\%Y)
and (-a)
o that is older than 20 days (mtime +20)
and (-a)

o that is NOT a directory (hence the ! character)

and it wacks it (rm -f).

Best Regards,
--
Todd H.
http://www.toddh.net/

Todd H.

unread,
Dec 4, 2006, 8:59:17 PM12/4/06
to
comp...@toddh.net (Todd H.) writes:

Oh, I forgot to mention that you can find the details of all this in
the man page for find.

$ man find

find ... incredible damned tool. You can do nearly anything with it.

Stephane CHAZELAS

unread,
Dec 5, 2006, 4:03:01 AM12/5/06
to
2006-12-04, 19:58(-06), Todd H.:

> "ame...@iwc.net" <ame...@iwc.net> writes:
>
>> Hey All,
>>
>> I saw this command in our cron. Was wondering what it really does. I
>> get lost after the part that looks in /export/home/oracle for files
>> starting with the date........
>>
>> /bin/find /export/home/oracle -name `date +\%Y`\*.* -a -mtime +20 -a !
>> -type d -exec rm -f {} \;
>
> It looks for stuff in that oracle subdirectory that:
> o with the name beginning with the current 4 digit year (date
> +\%Y)

And contains a dot.

There's a bug though it should have bee

-name "$(date +%Y)*.*"

otherwise, if there's a file called 2006*.foo in the current
directory, your shell would have expanded than.

> and (-a)
> o that is older than 20 days (mtime +20)
> and (-a)
>
> o that is NOT a directory (hence the ! character)
>
> and it wacks it (rm -f).

[...]


--
Stéphane

Binand Sethumadhavan

unread,
Dec 6, 2006, 11:10:49 AM12/6/06
to
Stephane CHAZELAS wrote:
> 2006-12-04, 19:58(-06), Todd H.:
>> "ame...@iwc.net" <ame...@iwc.net> writes:
>>> /bin/find /export/home/oracle -name `date +\%Y`\*.* -a -mtime +20 -a !
>>> -type d -exec rm -f {} \;
>> It looks for stuff in that oracle subdirectory that:
>> o with the name beginning with the current 4 digit year (date
>> +\%Y)
>
> And contains a dot.
>
> There's a bug though it should have bee
>
> -name "$(date +%Y)*.*"

There seems to be a second bug: if the files are named as per the date
they are created, then I think this cron will never be able to delete
files created between the 11th and 31st of December. By the time those
files match the -mtime criteria, they would stop matching the -name
criteria (since they year would have changed).

Binand

0 new messages