procmail
[Top] [All Lists]

Re: ls Error

2000-05-18 07:33:32
On May 16,  8:02am, Gary Funck wrote:
Subject: Re: ls Error
On May 15,  4:48am, SoloCDM wrote:
Subject: ls Error
Recently I executed the following command:

     rm -f dummy "ls -t msg.* | sed -e 1,900d"

I don't know the quoting convention for bash, but in csh, the
line above should read:
       rm -f dummy `ls -t msg.* | sed -e '1,900d'`

Also, if you're trying to remove the _first_ 900 messages, I
think you'll need to add the -r option to ls above:
       rm -f dummy `ls -tr msg.* | sed -e '1,900d'`

follow-up: I just noticed your deleteing the first 900 lines, which
are the files you want to save.  Your original formulation without
the -r was correct. So, remove the -r from my suggestion above.
It should read:
       rm -f dummy `ls -t msg.* | sed -e '1,900d'`


(WARNING: don't try this out on your only copy of the mail
archive directory!  Make sure that you work on a copy until
you have the bugs ironed out.)

find . -name 'msg.*' -print | xargs ls -1tr \
   | sed -e '1,900d' | xargs rm -f

and likewise:
find . -name 'msg.*' -print | xargs ls -1t \
   | sed -e '1,900d' | xargs rm -f

And here also:

set size = `find . -name 'msg.*' -print | wc -c`
# make it bigger, just to be sure, and in case some more files
# were created by the time we get around to deleting them
@ size = 2 * $size
find . -name 'msg.*' -print | xargs -s $size ls -1t \
   | sed -e '1,900d' | xargs rm -f

(note: in my original reply, I left out the 'sed' command.

And on the formulation with sort, you need to tell it that you
want the order of the sort reversed from ascnding to descending
order, so you'll need to add r to each field specification
in the sort command:

More complicated, but not subject to the vaguaries of xargs
limitations:

find . -name 'msg.*' -print | xargs ls -1l --full-time \
   | sort +9rn -10 +6rM -7 +7rn -8 +8r -9 \
   | sed -e '1,900d' | awk '{print $NF}' | xargs rm -f

<Prev in Thread] Current Thread [Next in Thread>