*BSD News Article 69774


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!solace!nntp.uio.no!news.cais.net!bofh.dot!news.mathworks.com!newsfeed.internetmci.com!in2.uu.net!nntp.teleport.com!usenet
From: merlyn@stonehenge.com (Randal L. Schwartz)
Newsgroups: comp.unix.bsd.freebsd.misc,comp.lang.perl.misc
Subject: Re: Deleting Empty Files
Date: 30 May 1996 03:48:59 -0700
Organization: Stonehenge Consulting Services; Portland, Oregon, USA
Lines: 31
Sender: merlyn@julie.teleport.com
Message-ID: <ukviheigh0.fsf@julie.teleport.com>
References: <31ab29fe.17230986@news.hq.af.mil> <31ACEB04.136A@fsl.noaa.gov>
Reply-To: merlyn@stonehenge.com
NNTP-Posting-Host: julie.teleport.com
In-reply-to: Sean Kelly's message of Wed, 29 May 1996 18:25:40 -0600
To: Sean Kelly <kelly@fsl.noaa.gov>
X-Newsreader: Gnus v5.0.15
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:20345 comp.lang.perl.misc:26693

>>>>> "Sean" == Sean Kelly <kelly@fsl.noaa.gov> writes:

Sean> Scott Gregory wrote:
>> Is there a utility or script that will delete files that are empty??

Sean> find <options> <dirs> -size 0 -type f | xargs rm -f

Which would be a bad thing to run as root over an untrusted (read:
any) directory tree.  Consider what happens if I:

	mkdir -p "duh\n/etc"
	touch "duh\n/etc/passwd"

Bingo.  Bye bye password file.

A better solution is a Perl solution (since you cross-posted to clpm,
I take it Perl is fair game here):

	find2perl <dirs> -size 0 -type f -eval unlink | perl

Much safer.  No chance to misinterpret a newline as a delimiter.

Perl is your friend.  Use Perl.

print "Just another Perl hacker,"
-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me