Re: OT: Alternatives to ls for sorting files by modification time
In article <[🔎] Pine.LNX.4.21.0209251000250.1686-100000@miami.datech2.er.heitec.net>,
Holger Rauch <Holger.Rauch@heitec.de> wrote:
>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
>
>($LS contains the path to "ls" and $TAIL the path to "tail")
>
>I want to remove the oldest $NUM_OF_FILES files and it seems to me that
>piping into tail fails when ls returns too many files.
No, you probably have lots of filed in $BACKUP_DIR/arc, so
the expression $BACKUP_DIR/arc/*.arc expands in more arguments
than is possible on the command line of ls.
How about
FILES=`$LS -t1 $BACKUP_DIR/arc | grep '\.arc$' | $TAIL -$NUM_OF_FILES`
This way, you let ls list all files, and filter the arc files
out with grep (note I left out '-l' which seems unnessecary)
If _that_ list gets too long you can always do
$LS -t1 $BACKUP_DIR/arc | grep '\.arc$' | $TAIL -$NUM_OF_FILES |
while read i
do
$RM -f $i
done
Mike.
--
Computers are useless, they only give answers. --Pablo Picasso
Reply to: