From owner-freebsd-stable@FreeBSD.ORG Fri Mar 4 19:05:47 2011 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D9C331065678 for ; Fri, 4 Mar 2011 19:05:47 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 3FFAE8FC1E for ; Fri, 4 Mar 2011 19:05:47 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id 7B2883593B1; Fri, 4 Mar 2011 20:05:45 +0100 (CET) Received: by turtle.stack.nl (Postfix, from userid 1677) id 6668A1739F; Fri, 4 Mar 2011 20:05:45 +0100 (CET) Date: Fri, 4 Mar 2011 20:05:45 +0100 From: Jilles Tjoelker To: Stephen Montgomery-Smith Message-ID: <20110304190545.GA38881@stack.nl> References: <4D6BD83B.3040609@missouri.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4D6BD83B.3040609@missouri.edu> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: FreeBSD Stable Subject: Re: Change in behavior to stat(1) X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2011 19:05:47 -0000 On Mon, Feb 28, 2011 at 11:15:39AM -0600, Stephen Montgomery-Smith wrote: > I had a little script that would remove broken links. I used to do it > like this: > if ! stat -L $link > /dev/null; then rm $link; fi > But recently (some time in February according to the CVS records) stat > was changed so that stat -L would use lstat(2) if the link is broken. > So I had to change it to > if stat -L $link | awk '{print $3}' | grep l > /dev/null; > then rm $link; fi > but it is a lot less elegant. > What is the proper accepted way to remove broken links? A better answer to your original question was already given, but for that command, isn't it sufficient to do if ! [ -e $link ]; then rm $link; fi All test(1)'s primaries that test things about files follow symlinks, except for -h/-L. -- Jilles Tjoelker