Date: Sat, 15 Aug 1998 13:52:13 +0200 (CEST) From: Malte Lance <malte.lance@gmx.net> To: Juergen Nickelsen <ni@tellique.de> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: removing files Message-ID: <13781.29695.192874.781242@neuron.webmore.de> In-Reply-To: <35D43DF9.B607F5D5@tellique.de> References: <35D195D9.CD9E1460@graphnet.com> <13777.47045.480782.154919@neuron.webmore.de> <35D43DF9.B607F5D5@tellique.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <ni@tellique.de> > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?13781.29695.192874.781242>