Unix questions - Command Question

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > December 2006 > Command Question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Command Question
amerar@iwc.net

2006-12-04, 7:24 pm

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.

2006-12-04, 7:24 pm

"amerar@iwc.net" <amerar@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 (-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.

2006-12-04, 7:24 pm

comphelp@toddh.net (Todd H.) writes:

> "amerar@iwc.net" <amerar@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).


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.

--
Todd H.
http://www.toddh.net/
Stephane CHAZELAS

2006-12-05, 7:32 am

2006-12-04, 19:58(-06), Todd H.:
> "amerar@iwc.net" <amerar@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 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

2006-12-06, 3:04 pm

Stephane CHAZELAS wrote:
> 2006-12-04, 19:58(-06), Todd H.:
>
> 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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com