Help deleting files older than 30 days. 
Author Message
 Help deleting files older than 30 days.

Hi,

I am trying to delete files in an archive directory that is older than
30 days. I want to write
a script which runs daily and deletes files which are more than 30 days
old.
I am trying to use find command as follows

   find . / -name \( tkgmp* \)  -atime -30 -exec rm {} \;

But its not working. Any help with a much better approach of doing this
would
be appreciated.

Thanks
Anand.



Fri, 20 Apr 2001 03:00:00 GMT  
 Help deleting files older than 30 days.


Quote:

>I am trying to delete files in an archive directory that is older than
>30 days. I want to write
>a script which runs daily and deletes files which are more than 30 days
>old.
>I am trying to use find command as follows

>   find . / -name \( tkgmp* \)  -atime -30 -exec rm {} \;

>But its not working. Any help with a much better approach of doing this
>would
>be appreciated.

You have a period as 1st argument followed by a slash as 2nd argument, with a
space separating them. On my system, that's a syntax error - both would be
interpretted as directories, but only one directory argument is supported.
Also, I believe you need to quote the pattern argument for the -name switch.
Try

find . -name 'tkgmp*'  -atime -30 -exec rm {} \;



Sat, 21 Apr 2001 03:00:00 GMT  
 Help deleting files older than 30 days.


Quote:
>Hi,

>I am trying to delete files in an archive directory that is older than
>30 days. I want to write
>a script which runs daily and deletes files which are more than 30 days
>old.
>I am trying to use find command as follows

>   find . / -name \( tkgmp* \)  -atime -30 -exec rm {} \;

Do you want to start from the current directory or the root directory?
Your command is starting from both places (it's redundant to specify an
additional directory when you specify the root).  I suspect you only want
to start from the current directory (which I assume is the archive
directory).

You need to quote the wildcard, so that it will be seen unexpanded when the
find command is processing the -name option.

You shouldn't have parentheses around the wildcard.

'-atime -30' matches files that have been accessed in *less* than 30 days,
not more.

So it should be:

find . -name 'tkgmp*' -atime +30 -exec rm {} \;

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.



Sat, 21 Apr 2001 03:00:00 GMT  
 Help deleting files older than 30 days.

Quote:

> Hi,

> I am trying to delete files in an archive directory that is older than
> 30 days. I want to write
> a script which runs daily and deletes files which are more than 30 days
> old.
> I am trying to use find command as follows

>    find . / -name \( tkgmp* \)  -atime -30 -exec rm {} \;

> But its not working. Any help with a much better approach of doing this
> would
> be appreciated.

> Thanks
> Anand.

Try:

find / -name tkgmp\* -atime +30 -exec rm {} \;

I asume you meant / as a starting point. If that's not the
case, use an absolute path.
I would use -print (or -ls) and redirect the output to a file
instead of -exec rm, until I'm sure it works.

Fabio



Sat, 21 Apr 2001 03:00:00 GMT  
 Help deleting files older than 30 days.

Quote:

> Hi,

> I am trying to delete files in an archive directory that is older than
> 30 days. I want to write
> a script which runs daily and deletes files which are more than 30 days
> old.
> I am trying to use find command as follows

>    find . / -name \( tkgmp* \)  -atime -30 -exec rm {} \;

> But its not working. Any help with a much better approach of doing this
> would
> be appreciated.

> Thanks
> Anand.

Try:

find / -name tkgmp\* -atime +30 -exec rm {} \;

I asume you meant / as a starting point. If that's not the
case, use an absolute path.
I would use -print (or -ls) and redirect the output to a file
instead of -exec rm, until I'm sure it works.

Fabio



Sat, 21 Apr 2001 03:00:00 GMT  
 Help deleting files older than 30 days.

Quote:

> find . -name 'tkgmp*' -atime +30 -exec rm {} \;

As many people have pointed out in the past there's a security problem
if you regularly do this on a directory that other people can write to because
they can exploit a race set up symlinks and delete arbirary files as
you.

I'm not going to explain it myself as anyone who cares can look back
on DejaNews.  Indead I believe Barry himself has given a particularly good
explaination of this in the past.

My question is: why has nobody done what stikes me as the obvious fix
for this? Namely added a new option (or maybe action) to find thus:

find . -cd -name 'tkgmp*' -atime +30 -exec rm {} \;

My idea is that '-cd' should modify -exec (and -ok) action so that
rather than subsituting the full path for {} find will only subtitute
the leafname and execute the command with an appropriate current
directory.

The alternative would be a separate -cdexec action.

Obviously this only makes sense when find is able to use fchdir().  In
situations where fchdir() is unavialable the -cd option should cause
the find to fail.  Actually this is not quite true, find could fake
the behaviour of fchdir() (with only the briefest race condition) by
fork()ing into n processes to handle n levels of directory but I'm not
sure that this is desirable.

Quote:

> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.

OK Barry, I've not mailed you but I think you are likley to be the
best person to critique this proposal.

Do you think my suggestion is sensible or is there still a gaping
security hole I've not considered?

Is there any reason I should not make this change to GNU find?

GNU find seems to have stagnated at 4.1 some years ago.  Since that
time I've found at least one bug myself.  -follow and -xstat do not
function correctly in some environments where stat() and lstat() are
inline functions.  (Trivial fix attached).

Is anyone maintaing GNU find?

--- /dev/fd/3   Fri Jul 25 13:17:15 1997

   struct stat sbuf;
   int (*ystat) ();

-  ystat = xstat == lstat ? stat : lstat;
+  ystat = dereference ? lstat : stat;
   if ((*ystat) (rel_pathname, &sbuf) != 0)
     {
       if (ystat == stat && errno == ENOENT)

--

  .  _\\__[oo   faeces from    | Phones: +44 121 471 3789 (home)

 .  l___\\    /~~) /~~[  /   [ | PGP-fp: D7 03 2A 4B D8 3A 05 37...
  # ll  l\\  ~~~~ ~   ~ ~    ~ | http://www.wcl.bham.ac.uk/~bam/
 ###LL  LL\\ (Brian McCauley)  |



Sun, 22 Apr 2001 03:00:00 GMT  
 Help deleting files older than 30 days.
:
: Try:
:
: find / -name tkgmp\* -atime +30 -exec rm {} \;
:
: I asume you meant / as a starting point. If that's not the
: case, use an absolute path.
: I would use -print (or -ls) and redirect the output to a file
: instead of -exec rm, until I'm sure it works.

Good point Fabio -- xargs is a good place to start for this.  Going off your
arguments:

    find / -name "tkgmp*" -atime +30 -print | xargs ls -l

(to check)

or
    find / -name "tkgmp*" -atime +30 -print | xargs rm

(to remove)

Chris
--
Christopher Y. Emura                |     2011 N. Shoreline Blvd.  MS 43L-748
MTS - Software Engineer             |     Mountain View, CA  94043




Tue, 24 Apr 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. list of directories older as 30 days

2. 30 day trial support in ProtectedProductSessionManager

3. 30-day evaluation version of ASMPUT now available

4. List & Label 30 day evaluation templates released

5. How can i get a 30 Day Trial Version License for VeriLogger Pro v6.5 ?(null)

6. Evaluation Activ-VHDL only for 30 days :(

7. 30 day evalution copy

8. 30-day trial copies of Compaq Visual Fortran now available

9. Implementing a 30-day trial period

10. SecWin master password & 30 day trial setting

11. 30 day count down has begun!

 

 
Powered by phpBB® Forum Software