[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Alternatives to ls for sorting files by modification time



On  0, Holger Rauch <Holger.Rauch@heitec.de> wrote:
> Hi Vineet!
> 
> Thanks a lot for your quick reply!
> 
> On Wed, 25 Sep 2002, Vineet Kumar wrote:
> 
> > [...]
> > processing the list, i.e. with xargs?  It's hard to make suggestions
> > without seeing what you're trying to do...
> 
> You're right ;-) What I'm doing is
> 
> FILES=`$LS -lt1 $BACKUP_DIR/arc/*.arc | $TAIL -$NUM_OF_FILES`
> for i in $FILES; do
>   $RM -f $i
> done

All I can say is... it works for me.  How many files in the directory
where you're having this fail?  It works for me in /usr/lib.

# ls /usr/lib -lt1 | wc -l
  841

Obviously I am not using 'rm -f $i' in this directory, I am using
'echo $i' instead.  Shouldn't make any difference.  It works for me
with $NUM_OF_FILES up to 800.

BTW, you probably want something more like this:

FILES=`$LS -lt1 $BACKUP_DIR/arc/*.arc | $AWK '{print $9;}' | $TAIL -$NUM_OF_FILES`
for i in $FILES; do
    $RM -f $i
done

otherwise you will get a lot of files with names like '-rw-r-----'
that rm can't delete for some mysterious reason.  Maybe that was your
problem?

Tom
-- 
Tom Cook
Information Technology Services, The University of Adelaide

"Not to limit itself to play in a sand vat."
	- Google translation of, "not to be stuck in a sandbox."

Get my GPG public key: https://pinky.its.adelaide.edu.au/~tkcook/tom.cook-at-adelaide.edu.au

Attachment: pgp3VJ6jgdXZk.pgp
Description: PGP signature


Reply to: