From owner-freebsd-questions Sat Aug 15 05:35:22 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id FAA23103 for freebsd-questions-outgoing; Sat, 15 Aug 1998 05:35:22 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from cyclone.degnet.baynet.de (cyclone.degnet.baynet.de [194.95.214.129]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id FAA23086 for ; Sat, 15 Aug 1998 05:35:20 -0700 (PDT) (envelope-from malte.lance@gmx.net) Received: from neuron.webmore.de (unverified [194.95.214.177]) by cyclone.degnet.baynet.de (EMWAC SMTPRS 0.83) with SMTP id ; Sat, 15 Aug 1998 14:36:03 +0200 Received: (from malte.lance@gmx.net) by neuron.webmore.de (8.8.8/8.8.8) id NAA05026; Sat, 15 Aug 1998 13:52:13 +0200 (CEST) From: Malte Lance MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sat, 15 Aug 1998 13:52:13 +0200 (CEST) To: Juergen Nickelsen Cc: freebsd-questions@FreeBSD.ORG Subject: Re: removing files In-Reply-To: <35D43DF9.B607F5D5@tellique.de> References: <35D195D9.CD9E1460@graphnet.com> <13777.47045.480782.154919@neuron.webmore.de> <35D43DF9.B607F5D5@tellique.de> X-Mailer: VM 6.43 under 20.4 "Emerald" XEmacs Lucid Message-ID: <13781.29695.192874.781242@neuron.webmore.de> Reply-To: malte.lance@gmx.net Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Juergen Nickelsen writes: > Malte Lance wrote: > > > > Let's say I have a directory with la.txt and foo.sh and 6 million > > > other files. > [...] > > > Can I issue a command that says: delete everything BUT la.txt and > > > foo.sh > [...] > > rm -f `/bin/ls /tmp/. | grep -v -e la.txt | grep -v -e foo.sh` > > You haven't tried that, have you? Never had the need for. > > First, your approach fails to delete the files "hola.txt" and > "foo.shut", which, though not mentioned, of course need to be removed as > well. To fix the RE-problem: rm -f `/bin/ls /tmp/. | grep -v -e '^la.txt$' | grep -v -e '^foo.sh$'` > > Second, deleting a large number of files as this one is tricky in > itself. Even "rm *" does not work, since the argument list passed to > exec is too long. ARG_MAX is 64K by default, which is easily reached by > 11000 Files with names 6 characters long. > > Provided the shell can handle a "*" expansion of 6 million files, it is > easiest to move the two files out of the way and pipe the "*" expansion > to xargs: > > mkdir .keep > mv la.txt foo.sh .keep > echo * | xargs rm If your shell expands "*" your ARG_MAX-complain should also apply to the "echo"-binary in the line above ??? > mv .keep/* . > rmdir .keep > > If the shell can't handle this(*), you'd have to make e. g. a perl > script which does the necessary opendir()/readdir() itself and erases > the files. > > (*) I did not want to try it with 6 million files. But then, it is > unwise to put so many files into one directory anyway. > Thanks for the lesson. Malte. > -- > Juergen Nickelsen > Tellique Kommunikationstechnik GmbH > Gustav-Meyer-Allee 25, 13355 Berlin, Germany > Tel. +49 30 46307-552 / Fax +49 30 46307-579 > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message