From owner-freebsd-questions@FreeBSD.ORG Wed Jan 27 20:11:51 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7C94A106566B for ; Wed, 27 Jan 2010 20:11:51 +0000 (UTC) (envelope-from bill@celestial.com) Received: from dorsai-02.celestial.com (dorsai-02.celestial.com [192.136.111.19]) by mx1.freebsd.org (Postfix) with ESMTP id 47DD08FC1F for ; Wed, 27 Jan 2010 20:11:51 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by dorsai-02.celestial.com (Postfix) with ESMTP id CB9F2205A8C4 for ; Wed, 27 Jan 2010 12:11:50 -0800 (PST) X-Virus-Scanned: amavisd-new at celestial.com Received: from dorsai-02.celestial.com ([127.0.0.1]) by localhost (dorsai-02.celestial.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9Eu0L5sysyVH for ; Wed, 27 Jan 2010 12:11:50 -0800 (PST) Received: from ayn.mi.celestial.com (hayek.celestial.com [192.136.111.12]) by dorsai-02.celestial.com (Postfix) with ESMTP id 9AD91205A668 for ; Wed, 27 Jan 2010 12:11:50 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by ayn.mi.celestial.com (Postfix) with ESMTP id 7991168EEF8E7; Wed, 27 Jan 2010 12:11:50 -0800 (PST) X-Virus-Scanned: amavisd-new at mi.celestial.com Received: from ayn.mi.celestial.com ([127.0.0.1]) by localhost (ayn.mi.celestial.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 12WVif1-iYLU; Wed, 27 Jan 2010 12:11:50 -0800 (PST) Received: by ayn.mi.celestial.com (Postfix, from userid 203) id 5BBBD68EEF8E5; Wed, 27 Jan 2010 12:11:50 -0800 (PST) Date: Wed, 27 Jan 2010 12:11:50 -0800 From: Bill Campbell To: freebsd-questions@freebsd.org Message-ID: <20100127201150.GB19557@ayn.mi.celestial.com> Mail-Followup-To: freebsd-questions@freebsd.org References: <4B6090FC.4070002@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4B6090FC.4070002@gmail.com> User-Agent: Mutt/1.5.19 OpenPKG/% (2009-01-05) Subject: Re: OT: finding every file not in a list X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd@celestial.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jan 2010 20:11:51 -0000 On Wed, Jan 27, 2010, Aryeh M. Friedman wrote: > I have a list of files that should be in a dir tree and want to remove > any files from the tree not in list (i.e. if it is on the list keep it > else rm it)... any quick way to do this? One way to do this that I use quite frequently uses the comm program to compare lists, something like cd /path-to-dir1 find . -type f | sort > /tmp/list1 cd /path-to-dir2 find . -type f | sort > /tmp/list2 comm -23 /tmp/list1 /tmp/list2 > /tmp/filesinlist1notinlist2 comm -13 /tmp/list1 /tmp/list2 > /tmp/filesinlist2notinlist1 comm -12 /tmp/list1 /tmp/list2 > /tmp/filescommontolist1andlist2 Then of course one could remove files in list1 not in list2 with: xargs rm < /tmp/filesinlist1notinlist2 NOTE: The xargs command will not work if the files contain whitespace. Bill -- INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way Voice: (206) 236-1676 Mercer Island, WA 98040-0820 Fax: (206) 232-9186 Skype: jwccsllc (206) 855-5792 Criminals love gun control it makes their jobs safer.