From owner-freebsd-questions Tue Mar 9 2:11: 0 1999 Delivered-To: freebsd-questions@freebsd.org Received: from alpha.comkey.com.au (alpha.comkey.com.au [203.9.152.215]) by hub.freebsd.org (Postfix) with SMTP id 13C5414FB4 for ; Tue, 9 Mar 1999 02:10:48 -0800 (PST) (envelope-from gjb@comkey.com.au) Received: (qmail 9250 invoked by uid 1001); 9 Mar 1999 10:07:50 -0000 Message-ID: <19990309100750.9249.qmail@alpha.comkey.com.au> X-Posted-By: GBA-Post 1.04 06-Feb-1999 X-PGP-Fingerprint: 5A91 6942 8CEA 9DAB B95B C249 1CE1 493B 2B5A CE30 Date: Tue, 09 Mar 1999 20:07:50 +1000 From: Greg Black To: cjclark@home.com Cc: chris@tci.com, mikegoe@ibm.net, freebsd-questions@FreeBSD.ORG Subject: Re: /var -- Device Busy References: <199903082028.PAA23450@cc942873-a.ewndsr1.nj.home.com> In-reply-to: <199903082028.PAA23450@cc942873-a.ewndsr1.nj.home.com> of Mon, 08 Mar 1999 15:28:27 EST Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > > > Hmmm...I've always used rm -r to remove > > > > directories...didn't even realize there was a rmdir > > > > command...I guess there's many ways to do the same thing... > > > > :) > > > > > > Are you sure you weren't using rm -rf? > > > > Do the following and answer your own question: > > > > mkdir testdir > > touch testdir/file > > rm -r testdir > > > > Of course, if you are not root and if some elements in the tree > > are read-only, then you'll get asked about them without the -f > > flag -- but the -f flag will not allow you to rm anything that > > you could not rm without using -f (which means that -f has no > > meaning when used by root). > > Not true. The '-f' flag will prevent error messages about files that > do not exist as well as cause 'rm' to exit on a 0 in such a situation. This is a bizarre nit to pick. The context is using rm -r interactively to remove directories (and their contents). Given that starting point, the only way that root would get a different outcome with the -f flag is if a directory or file listed on the command line didn't exist, in which case the command would silently fail. So adding -f doesn't buy you anything useful in this unique situation and changes nothing in the context of interest which was in the recursive operation inside the director{y,ies}. > This can be important in scripts and makefiles. It's my view that scripts or makefiles that run rm -rf on a non-existent directory are broken. It's one thing to dash about using something like rm -f $(OBJS) in a makefile without first checking if the files exist (although a good case can be made for not doing this, either) but it's insane to do a recursive rm on stuff that's not there. As an illustration, instead of the common form: clean: rm -f $(PROGS) $(OBJS) we can use: clean: .for F in $(PROGS) $(OBJS) .if exists ($F) rm $F .endif .endfor This way, we don't try to remove stuff that doesn't exist and we get meaningful error messages if we have it wrong. If we don't want this to stop the make from continuing, we all know (or know how to discover) the syntax for that. Similarly, in a shell script, rather than: rm -f $FILES we can use: for F in $FILES ; do [ -e $F ] && rm $F ; done for the same benefits. -- Greg Black To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message