|
Home > Archive > Unix Shell > February 2007 > To remove the old files of more than one hour
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 |
To remove the old files of more than one hour
|
|
| Guytou 2007-02-24, 7:21 am |
| Hi,
I use a Unix treatment which turns each 3 minutes and generates many files
logs.
I will only like to keep the old logs of less than one hour and to remove
the others.
The order find with the option mtime makes of research in a number of day.
I thus divided the day by 24 to have the hour. But my script is not good
Here my script:
#!bin/ksh
find. - mtime +1/24 - name ' * log' - * print - * exec rm \;
CR=$?
if [ $$CR - 0 ]
echo " Problem with find or rm of the old files of more than one hour "
exit $$CR
else
echo " the files old log of more than one hour are removed "
fi
exit 0
Who can correct it to me?
I will like to know how to use " find - mtime " with the hours and not the
days.
If it is not possible with find to remove the old files of more than one
hour,
can one do it with another UNIX command?
By advance thank you
Cordially
GUYTOU
| |
| Bill Marcum 2007-02-24, 7:21 am |
| On Sat, 24 Feb 2007 09:27:22 +0100, Guytou
<mapasa@free.fr> wrote:
>
>
> Hi,
>
> I use a Unix treatment which turns each 3 minutes and generates many files
> logs.
> I will only like to keep the old logs of less than one hour and to remove
> the others.
> The order find with the option mtime makes of research in a number of day.
> I thus divided the day by 24 to have the hour. But my script is not good
>
> Here my script:
>
> #!bin/ksh
> find. - mtime +1/24 - name ' * log' - * print - * exec rm \;
> CR=$?
> if [ $$CR - 0 ]
> echo " Problem with find or rm of the old files of more than one hour "
>
> exit $$CR
> else
> echo " the files old log of more than one hour are removed "
> fi
> exit 0
>
> Who can correct it to me?
>
If you have GNU find you can use -mmin. Otherwise you can use touch and
find -newer.
--
Mix's Law:
There is nothing more permanent than a temporary building.
There is nothing more permanent than a temporary tax.
| |
| stevodestructo@gmail.com 2007-02-27, 1:24 am |
| On Feb 24, 12:27 am, "Guytou" <map...@free.fr> wrote:
> Hi,
>
> I use a Unix treatment which turns each 3 minutes and generates many files
> logs.
> I will only like to keep the old logs of less than one hour and to remove
> the others.
> The order find with the option mtime makes of research in a number of day.
> I thus divided the day by 24 to have the hour. But my script is not good
>
> Here my script:
>
> #!bin/ksh
> find. - mtime +1/24 - name ' * log' - * print - * exec rm \;
> CR=$?
> if [ $$CR - 0 ]
> echo " Problem with find or rm of the old files of more than one hour "
>
> exit $$CR
> else
> echo " the files old log of more than one hour are removed "
> fi
> exit 0
>
> Who can correct it to me?
>
> I will like to know how to use " find - mtime " with the hours and not the
> days.
> If it is not possible with find to remove the old files of more than one
> hour,
> can one do it with another UNIX command?
>
> By advance thank you
>
> Cordially
>
> GUYTOU
Maybe this would work:
find . -mtime -1 -type f -name "*log" -printf "%p\n" | xargs -i rm -f
{}
I'd put something like this first though, just to make sure you don't
go on a rm rampage.
find . -mtime -1 -type f -name "*log" -printf "%p\n" | xargs -i echo -
ne "file {}\n"
~ stevo
| |
| stevodestructo@gmail.com 2007-02-27, 1:24 am |
| On Feb 26, 8:31 pm, stevodestru...@gmail.com wrote:
> On Feb 24, 12:27 am, "Guytou" <map...@free.fr> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
> Maybe this would work:
> find . -mtime -1 -type f -name "*log" -printf "%p\n" | xargs -i rm -f
> {}
>
> I'd put something like this first though, just to make sure you don't
> go on a rm rampage.
>
> find . -mtime -1 -type f -name "*log" -printf "%p\n" | xargs -i echo -
> ne "file {}\n"
>
> ~ stevo
woops... make -mtime -1 to "-mtime +1" greater than... sorry about
that.
| |
| Bill Marcum 2007-02-27, 1:24 am |
| On 26 Feb 2007 20:35:33 -0800, stevodestructo@gmail.com
<stevodestructo@gmail.com> wrote:
>
>
> woops... make -mtime -1 to "-mtime +1" greater than... sorry about
> that.
>
The OP wanted to find files more than 1 hour old.
--
A kiss is a course of procedure, cunningly devised, for the mutual
stoppage of speech at a moment when words are superfluous.
| |
| stevodestructo@gmail.com 2007-02-27, 1:24 am |
| On Feb 26, 10:29 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 26 Feb 2007 20:35:33 -0800, stevodestru...@gmail.com <stevodestru...@gmail.com> wrote:
>
>[snip]
> The OP wanted to find files more than 1 hour old.
run it with -mtime +1 and it will.
| |
| Stephane CHAZELAS 2007-02-27, 1:19 pm |
| 2007-02-26, 22:56(-08), stevodestructo@gmail.com:
> On Feb 26, 10:29 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
>
>
> run it with -mtime +1 and it will.
No, depending on the find implementation that will remove files
that were last modified more than 48 hours ago (now - filetime /
86400 > 1) or for some non-POSIX find implementations before
yesterday, so depending on the hour when you run that command,
that will remove files modified more than x hours ago, where x
is comprised between 24 and 48.
So, the files that will be removed will be more than one hour
old, but not all the more than one hour old files will be
removed.
--
Stéphane
| |
| Randal L. Schwartz 2007-02-27, 7:16 pm |
| >>>>> "Guytou" == Guytou <mapasa@free.fr> writes:
Guytou> I use a Unix treatment which turns each 3 minutes and generates many
Guytou> files logs.
Guytou> I will only like to keep the old logs of less than one hour and to
Guytou> remove the others.
cd /the/right/directory && PERL -e 'unlink { grep -M > 1/24 } glob q{*}'
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment PERL training!
--
Posted via a free Usenet account from http://www.teranews.com
| |
| Guytou 2007-02-28, 7:17 pm |
| thank you for your assistance
"Randal L. Schwartz" <merlyn@stonehenge.com> a écrit dans le message de
news: 868xejp8c8.fsf@blue.stonehenge.com...
>
> Guytou> I use a Unix treatment which turns each 3 minutes and generates
> many
> Guytou> files logs.
>
> Guytou> I will only like to keep the old logs of less than one hour and to
> Guytou> remove the others.
>
> cd /the/right/directory && PERL -e 'unlink { grep -M > 1/24 } glob q{*}'
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
> 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
> training!
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>
|
|
|
|
|