PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Removing files but maintaining last 15
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Removing files but maintaining last 15

Réponse
 
LinkBack Outils de la discussion
Vieux 02/05/2008, 20h48   #1
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Removing files but maintaining last 15

Hi:

I´m looking for a way to remove all *.trw files in a specified
directory, but maintaining the last 15 *.trw files...

Thank You for your .
  Réponse avec citation
Vieux 02/05/2008, 21h03   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On 2008-05-02, apogeusistemas@gmail.com <apogeusistemas@gmail.com> wrote:
>
>
> Hi:
>
> I´m looking for a way to remove all *.trw files in a specified
> directory, but maintaining the last 15 *.trw files...
>
> Thank You for your .


How do you define last? If you mean last modified:
ls -t *.trw | tail -n +16 | xargs rm

  Réponse avec citation
Vieux 02/05/2008, 21h05   #3
Chris Mattern
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On 2008-05-02, apogeusistemas@gmail.com <apogeusistemas@gmail.com> wrote:
> Hi:
>
> I´m looking for a way to remove all *.trw files in a specified
> directory, but maintaining the last 15 *.trw files...


How are you defining "last"? Last in alphabetical order? The most
recently modified? Some other way?

I assume by "maintaining" you mean you want remove all *except*
the "last" 15 (whatever "last" means).

>
> Thank You for your .



--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
  Réponse avec citation
Vieux 02/05/2008, 21h10   #4
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On May 2, 5:05pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:
> On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:
>
> > Hi:

>
> > I´m looking for a way to remove all *.trw files in a specified
> > directory, but maintaining the last 15 *.trw files...

>
> How are you defining "last"? Last in alphabetical order? The most
> recently modified? Some other way?
>
> I assume by "maintaining" you mean you want remove all *except*
> the "last" 15 (whatever "last" means).
>
>
>
> > Thank You for your .

>
> --
> Christopher Mattern
>
> NOTICE
> Thank you for noticing this new notice
> Your noticing it has been noted
> And will be reported to the authorities


Last 15 files created...

thanks
  Réponse avec citation
Vieux 02/05/2008, 21h27   #5
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

apogeusistemas@gmail.com wrote:
> On May 2, 5:05 pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:
>> On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:
>>
>>> I´m looking for a way to remove all *.trw files in a specified
>>> directory, but maintaining the last 15 *.trw files...

>> How are you defining "last"? Last in alphabetical order? The most
>> recently modified? Some other way?
>>
>> I assume by "maintaining" you mean you want remove all *except*
>> the "last" 15 (whatever "last" means).

>
> Last 15 files created...


You can't do that. Unix doesn't store the creation date anywhere.


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
  Réponse avec citation
Vieux 02/05/2008, 22h07   #6
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On May 2, 5:27pm, "John W. Krahn" <some...@example.com> wrote:
> apogeusiste...@gmail.com wrote:
> > On May 2, 5:05 pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:
> >> On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:

>
> >>> I´m looking for a way to remove all *.trw files in a specified
> >>> directory, but maintaining the last 15 *.trw files...
> >> How are you defining "last"? Last in alphabetical order? The most
> >> recently modified? Some other way?

>
> >> I assume by "maintaining" you mean you want remove all *except*
> >> the "last" 15 (whatever "last" means).

>
> > Last 15 files created...

>
> You can't do that. Unix doesn't store the creation date anywhere.
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall


but how could I sort using date and hour ?
  Réponse avec citation
Vieux 02/05/2008, 22h11   #7
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15



On 5/2/2008 4:07 PM, apogeusistemas@gmail.com wrote:
> On May 2, 5:27 pm, "John W. Krahn" <some...@example.com> wrote:
>
>>apogeusiste...@gmail.com wrote:
>>
>>>On May 2, 5:05 pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:
>>>
>>>>On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:
>>>
>>>>>I´m looking for a way to remove all *.trw files in a specified
>>>>>directory, but maintaining the last 15 *.trw files...
>>>>
>>>>How are you defining "last"? Last in alphabetical order? The most
>>>>recently modified? Some other way?
>>>
>>>>I assume by "maintaining" you mean you want remove all *except*
>>>>the "last" 15 (whatever "last" means).
>>>
>>>Last 15 files created...

>>
>>You can't do that. Unix doesn't store the creation date anywhere.
>>
>>John
>>--
>>Perl isn't a toolbox, but a small machine shop where you
>>can special-order certain sorts of tools at low cost and
>>in short order. -- Larry Wall

>
>
> but how could I sort using date and hour ?


date and hour of what? You can use last access time or last modification time,
you just can't use creation time.

Ed.

  Réponse avec citation
Vieux 02/05/2008, 22h55   #8
Chris Mattern
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On 2008-05-02, apogeusistemas@gmail.com <apogeusistemas@gmail.com> wrote:
> On May 2, 5:27pm, "John W. Krahn" <some...@example.com> wrote:
>> apogeusiste...@gmail.com wrote:
>> > On May 2, 5:05 pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:
>> >> On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:

>>
>> >>> I´m looking for a way to remove all *.trw files in a specified
>> >>> directory, but maintaining the last 15 *.trw files...
>> >> How are you defining "last"? Last in alphabetical order? The most
>> >> recently modified? Some other way?

>>
>> >> I assume by "maintaining" you mean you want remove all *except*
>> >> the "last" 15 (whatever "last" means).

>>
>> > Last 15 files created...

>>
>> You can't do that. Unix doesn't store the creation date anywhere.
>>

>
> but how could I sort using date and hour ?


A number of ways. Unix stores mtime (last time the file's
data was modified), atime (last time the file's data was
read) and ctime (last time the file's inode data was
modified; this can changed by changing a file's permissions,
ownership or using ln or rm to create or destroy links
to the file). Which one do you want to use?


--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
  Réponse avec citation
Vieux 02/05/2008, 22h57   #9
Chris Mattern
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On 2008-05-02, Ed Morton <morton@lsupcaemnt.com> wrote:
>
>
> On 5/2/2008 4:07 PM, apogeusistemas@gmail.com wrote:
>> On May 2, 5:27 pm, "John W. Krahn" <some...@example.com> wrote:
>>
>>>apogeusiste...@gmail.com wrote:
>>>
>>>>On May 2, 5:05 pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:
>>>>
>>>>>On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:
>>>>
>>>>>>I´m looking for a way to remove all *.trw files in a specified
>>>>>>directory, but maintaining the last 15 *.trw files...
>>>>>
>>>>>How are you defining "last"? Last in alphabetical order? The most
>>>>>recently modified? Some other way?
>>>>
>>>>>I assume by "maintaining" you mean you want remove all *except*
>>>>>the "last" 15 (whatever "last" means).
>>>>
>>>>Last 15 files created...
>>>
>>>You can't do that. Unix doesn't store the creation date anywhere.
>>>

>>
>>
>> but how could I sort using date and hour ?

>
> date and hour of what? You can use last access time or last modification time,
> you just can't use creation time.
>

There's also change time; if they're not changing around permissions or
ownerships, or using hard links to the file, it can be used as a proxy
for creation time.

--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
  Réponse avec citation
Vieux 02/05/2008, 23h35   #10
apogeusistemas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On 2 maio, 18:57, Chris Mattern <sys...@sumire.gwu.edu> wrote:
> On 2008-05-02, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>
>
>
>
> > On 5/2/2008 4:07 PM, apogeusiste...@gmail.com wrote:
> >> On May 2, 5:27 pm, "John W. Krahn" <some...@example.com> wrote:

>
> >>>apogeusiste...@gmail.com wrote:

>
> >>>>On May 2, 5:05 pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:

>
> >>>>>On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:

>
> >>>>>>I´m looking for a way to remove all *.trw files in a specified
> >>>>>>directory, but maintaining the last 15 *.trw files...

>
> >>>>>How are you defining "last"? Last in alphabetical order? The most
> >>>>>recently modified? Some other way?

>
> >>>>>I assume by "maintaining" you mean you want remove all *except*
> >>>>>the "last" 15 (whatever "last" means).

>
> >>>>Last 15 files created...

>
> >>>You can't do that. Unix doesn't store the creation date anywhere.

>
> >> but how could I sort using date and hour ?

>
> > date and hour of what? You can use last access time or last modificationtime,
> > you just can't use creation time.

>
> There's also change time; if they're not changing around permissions or
> ownerships, or using hard links to the file, it can be used as a proxy
> for creation time.
>
> --
> Christopher Mattern
>
> NOTICE
> Thank you for noticing this new notice
> Your noticing it has been noted
> And will be reported to the authorities- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -


I create this script, but it's removing last modified files, but I
want exactly the opposite.

ls -ltr *.trw | tail +15 | awk '{ print $9 }' > x.lis
for file in `cat x.lis`
do
ls -l $file
#rm $file
done


issuing ls -ltr I get this ->

ls -ltr *.trw

-rw-r----- 1 oradm dba 25085423 May 2 09:51
dm581_ora_10744.trw
-rw-r----- 1 oradm dba 25085487 May 2 09:51
dm789_ora_10742.trw
-rw-r----- 1 oradm dba 790 May 2 10:03
dm532_reco_27372.trw
-rw-r----- 1 oradm dba 862 May 2 10:11
dm351_ora_10969.trw
-rw-r----- 1 oradm dba 25240999 May 2 10:21
dm676_ora_10881.trw
-rw-r----- 1 oradm dba 25240991 May 2 10:21
dm321_ora_10879.trw
-rw-rw---- 1 oradm dba 755 May 2 10:37
dm143_ora_3295.trw
-rw-rw---- 1 oradm dba 753 May 2 10:37
dm989_ora_3254.trw

but I need any ls command to show me this ->

-rw-rw---- 1 oradm dba 753 May 2 10:37
dm989_ora_3254.trw
-rw-rw---- 1 oradm dba 755 May 2 10:37
dm143_ora_3295.trw
-rw-r----- 1 oradm dba 25240991 May 2 10:21
dm321_ora_10879.trw
-rw-r----- 1 oradm dba 25240999 May 2 10:21
dm676_ora_10881.trw
-rw-r----- 1 oradm dba 862 May 2 10:11
dm351_ora_10969.trw
-rw-r----- 1 oradm dba 790 May 2 10:03
dm532_reco_27372.trw
-rw-r----- 1 oradm dba 25085487 May 2 09:51
dm789_ora_10742.trw
-rw-r----- 1 oradm dba 25085423 May 2 09:51
dm581_ora_10744.trw
  Réponse avec citation
Vieux 03/05/2008, 01h15   #11
mop2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

Caution with the alias "ls":

x=1;/bin/ls -1dt *.trw|while read F;do
if [ $x -gt 15 ];then
echo rm $F
else
echo ok $F
x=$[x+1]
fi
done



apogeusiste...@gmail.com wrote:
> On 2 maio, 18:57, Chris Mattern <sys...@sumire.gwu.edu> wrote:
> > On 2008-05-02, Ed Morton <mor...@lsupcaemnt.com> wrote:
> >
> >
> >
> >
> >
> > > On 5/2/2008 4:07 PM, apogeusiste...@gmail.com wrote:
> > >> On May 2, 5:27 pm, "John W. Krahn" <some...@example.com> wrote:

> >
> > >>>apogeusiste...@gmail.com wrote:

> >
> > >>>>On May 2, 5:05 pm, Chris Mattern <sys...@sumire.gwu.edu> wrote:

> >
> > >>>>>On 2008-05-02, apogeusiste...@gmail.com <apogeusiste...@gmail.com> wrote:

> >
> > >>>>>>I�m looking for a way to remove all *.trw files in a specified
> > >>>>>>directory, but maintaining the last 15 *.trw files...

> >
> > >>>>>How are you defining "last"? �Last in alphabetical order? �The most
> > >>>>>recently modified? �Some other way?

> >
> > >>>>>I assume by "maintaining" you mean you want remove all *except*
> > >>>>>the "last" 15 (whatever "last" means).

> >
> > >>>>Last 15 files created...

> >
> > >>>You can't do that. �Unix doesn't store the creation date anywhere.

> >
> > >> but how could I sort using date and hour ?

> >
> > > date and hour of what? You can use last access time or last modification time,
> > > you just can't use creation time.

> >
> > There's also change time; if they're not changing around permissions or
> > ownerships, or using hard links to the file, it can be used as a proxy
> > for creation time.
> >
> > --
> > � � � � � � �Christopher Mattern
> >
> > NOTICE
> > Thank you for noticing this new notice
> > Your noticing it has been noted
> > And will be reported to the authorities- Ocultar texto entre aspas -
> >
> > - Mostrar texto entre aspas -

>
> I create this script, but it's removing last modified files, but I
> want exactly the opposite.
>
> ls -ltr *.trw | tail +15 | awk '{ print $9 }' > x.lis
> for file in `cat x.lis`
> do
> ls -l $file
> #rm $file
> done
>
>
> issuing ls -ltr I get this ->
>
> ls -ltr *.trw
>
> -rw-r----- 1 oradm dba 25085423 May 2 09:51
> dm581_ora_10744.trw
> -rw-r----- 1 oradm dba 25085487 May 2 09:51
> dm789_ora_10742.trw
> -rw-r----- 1 oradm dba 790 May 2 10:03
> dm532_reco_27372.trw
> -rw-r----- 1 oradm dba 862 May 2 10:11
> dm351_ora_10969.trw
> -rw-r----- 1 oradm dba 25240999 May 2 10:21
> dm676_ora_10881.trw
> -rw-r----- 1 oradm dba 25240991 May 2 10:21
> dm321_ora_10879.trw
> -rw-rw---- 1 oradm dba 755 May 2 10:37
> dm143_ora_3295.trw
> -rw-rw---- 1 oradm dba 753 May 2 10:37
> dm989_ora_3254.trw
>
> but I need any ls command to show me this ->
>
> -rw-rw---- 1 oradm dba 753 May 2 10:37
> dm989_ora_3254.trw
> -rw-rw---- 1 oradm dba 755 May 2 10:37
> dm143_ora_3295.trw
> -rw-r----- 1 oradm dba 25240991 May 2 10:21
> dm321_ora_10879.trw
> -rw-r----- 1 oradm dba 25240999 May 2 10:21
> dm676_ora_10881.trw
> -rw-r----- 1 oradm dba 862 May 2 10:11
> dm351_ora_10969.trw
> -rw-r----- 1 oradm dba 790 May 2 10:03
> dm532_reco_27372.trw
> -rw-r----- 1 oradm dba 25085487 May 2 09:51
> dm789_ora_10742.trw
> -rw-r----- 1 oradm dba 25085423 May 2 09:51
> dm581_ora_10744.trw

  Réponse avec citation
Vieux 06/05/2008, 14h19   #12
Geoff Clare
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

Chris Mattern wrote:

> On 2008-05-02, Ed Morton <morton@lsupcaemnt.com> wrote:
>>
>> You can use last access time or last modification time,
>> you just can't use creation time.
>>

> There's also change time; if they're not changing around permissions or
> ownerships, or using hard links to the file, it can be used as a proxy
> for creation time.


No it can't. The ctime is also updated when the file is written to.

--
Geoff Clare <netnews@gclare.org.uk>
  Réponse avec citation
Vieux 06/05/2008, 15h24   #13
Scott McMillan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing files but maintaining last 15

On Fri, 2 May 2008 15:35:44 -0700 (PDT), apogeusistemas@gmail.com
wrote:

<snip>

>
>I create this script, but it's removing last modified files, but I
>want exactly the opposite.
>
>ls -ltr *.trw | tail +15 | awk '{ print $9 }' > x.lis
>for file in `cat x.lis`
>do
>ls -l $file
>#rm $file
>done
>
>
>issuing ls -ltr I get this ->
>
>ls -ltr *.trw
>
>-rw-r----- 1 oradm dba 25085423 May 2 09:51
>dm581_ora_10744.trw
>-rw-r----- 1 oradm dba 25085487 May 2 09:51
>dm789_ora_10742.trw
>-rw-r----- 1 oradm dba 790 May 2 10:03
>dm532_reco_27372.trw
>-rw-r----- 1 oradm dba 862 May 2 10:11
>dm351_ora_10969.trw
>-rw-r----- 1 oradm dba 25240999 May 2 10:21
>dm676_ora_10881.trw
>-rw-r----- 1 oradm dba 25240991 May 2 10:21
>dm321_ora_10879.trw
>-rw-rw---- 1 oradm dba 755 May 2 10:37
>dm143_ora_3295.trw
>-rw-rw---- 1 oradm dba 753 May 2 10:37
>dm989_ora_3254.trw


As expected. You told ls to reverse the order when you supplied the -r
option...

>
>but I need any ls command to show me this ->
>
>-rw-rw---- 1 oradm dba 753 May 2 10:37
>dm989_ora_3254.trw
>-rw-rw---- 1 oradm dba 755 May 2 10:37
>dm143_ora_3295.trw
>-rw-r----- 1 oradm dba 25240991 May 2 10:21
>dm321_ora_10879.trw
>-rw-r----- 1 oradm dba 25240999 May 2 10:21
>dm676_ora_10881.trw
>-rw-r----- 1 oradm dba 862 May 2 10:11
>dm351_ora_10969.trw
>-rw-r----- 1 oradm dba 790 May 2 10:03
>dm532_reco_27372.trw
>-rw-r----- 1 oradm dba 25085487 May 2 09:51
>dm789_ora_10742.trw
>-rw-r----- 1 oradm dba 25085423 May 2 09:51
>dm581_ora_10744.trw


Then remove the -r option, as in ls -lt


Scott McMillan
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,26752 seconds with 21 queries