From owner-freebsd-questions Fri Aug 14 06:39:40 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id GAA27029 for freebsd-questions-outgoing; Fri, 14 Aug 1998 06:39:40 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from picasso.tellique.de (picasso.tellique.de [62.144.106.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id GAA27000 for ; Fri, 14 Aug 1998 06:39:27 -0700 (PDT) (envelope-from ni@tellique.de) Received: from tellique.de (nolde.tellique.de [62.144.106.52]) by picasso.tellique.de (8.8.8/8.8.8) with ESMTP id PAA00723; Fri, 14 Aug 1998 15:38:55 +0200 (MET DST) Message-ID: <35D43DF9.B607F5D5@tellique.de> Date: Fri, 14 Aug 1998 15:39:05 +0200 From: Juergen Nickelsen Organization: Tellique GmbH X-Mailer: Mozilla 4.05 [en] (X11; I; FreeBSD 2.2.7-STABLE i386) MIME-Version: 1.0 To: freebsd-questions@FreeBSD.ORG Subject: Re: removing files References: <35D195D9.CD9E1460@graphnet.com> <13777.47045.480782.154919@neuron.webmore.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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? 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. 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 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. -- 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