Re: Removing Files with a specified date.

From: Tony Lawrence (foo_at_pcunix.com)
Date: 04/26/05


Date: Tue, 26 Apr 2005 11:51:54 -0400

Bill Vermillion wrote:
> In article <o_-dnTcFEI8p4vDfRVn-2g@comcast.com>,
> Tony Lawrence <foo@pcunix.com> wrote:
>
>>Andre Georgel wrote:
>>
>>>Le Fri, 22 Apr 2005 10:16:10 -0500, "Ronald J Marchand"
>>><ron@rojomar.com> a écrit :
>>>
>>>
>>>
>>>>"Andre Georgel" <agl@nospam.com> wrote in message
>>>>news:bdkh615qm7naguqe9uibbji9t2b46qobur@4ax.com...
>>>>
>>>>
>>>>>Hi all,
>>>>>
>>>>>I'm not fine in shell and I want to find a shell (KSH) command to
>>>>>remove, in a directory, all the files with a specified date in the
>>>>>command.
>>>>>
>>>>
>>>>man find
>>>>
>>>>you can select by days old and add -exec rm {} to the end of it
>>>>
>>>>Ron
>>>>
>>>
>>>Thank you for the help, I've make some tests all it's OK, but I'd
>>>prefere a solution with an explicite date (ex. 12 DEC 2004).
>>>
>>>---------------------------------------------------
>>>Andre Georgel
>>>
>>>Pour répondre et obtenir l'adresse Email :
>>>http://marreduspam.com/ade0b300
>>>
>>>"La perfection n'est pas lorsqu'il n'y a plus rien à
>>>ajouter, mais lorsque qu'il n'y a plus rien à enlever."
>>>"Perfection is not when there is nothing to add, but
>>>when there is nothing to remove."
>>>
>>>(A. de Saint Exupery)
>>>----------------------------------------------------
>>>
>
>
>>Well, that's extremely easy with Perl, but if you must do it with
>>the shell, it's relatively easy (for a specific directory) with
>>an ls -l piped to a grep for the date passed through cut and
>>finally handed to rm.
>
>
> At first glance using the output of 'ls -l' might seem easy,
> but I think that could be quite awkward considering that date
> display of an 'ls -l' is not the same for file that are less than 6
> months old versus those older than 6 months. The newest file
> are in Month/Day/Hour/Minute form while older files are
> displayed at Month/Day/Year.
>
> That is because you are working with _displayed_ times.
>
> If you used a script to do the above you'd have to modify for the
> date ranges to take this into account. I think another post that
> used two dates for find with using the 'not newer' and the 'newer'
> to get only the dates in a specific range would be selected.
>
> For the 'ls' implementations that support the "T" flag which always
> displays the complete time your solution could work.
>
> And of course there is a big 'GOTCHA' if you need to be exact
> and the machine is more than just locally accessed, as
> the timezone will display local time which may or may not give
> you what you want.
>
> In cases where it's critical, don't remove the files but move the
> files elsewhere to MAKE SURE before they go *poof*.
>
> So often the seemingly simple solutions can cause the most grief.
>
> Bill
>

Well, to my mind the "simple" solution is to use Perl with a stat on
each file..

:-)

-- 
Tony Lawrence
Unix/Linux/Mac OS X  resources: http://aplawrence.com


Relevant Pages

  • Re: Removing Files with a specified date.
    ... That flag seems to be unknown to many. ... Bill Vermillion - bv @ wjv. ...
    (comp.unix.sco.misc)
  • Re: VNC Server Problem
    ... >with the top line of the Perl program not finding Perl on ... I've seen something similar on a non-SCO system. ... Bill Vermillion - bv @ wjv. ...
    (comp.unix.sco.misc)
  • Re: incrementing a string by a certain value
    ... I am fairly new to Perl. ... It's extremely easy if you stick to the ASCII table, ... > and my less than elegant example shows you why; ...
    (comp.lang.perl.misc)