From owner-freebsd-questions Sat Aug 26 9:29:35 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by hub.freebsd.org (Postfix) with ESMTP id 460D737B423 for ; Sat, 26 Aug 2000 09:29:30 -0700 (PDT) Received: (from dan@localhost) by dan.emsphone.com (8.9.3/8.9.3) id LAA28900; Sat, 26 Aug 2000 11:29:24 -0500 (CDT) (envelope-from dan) Date: Sat, 26 Aug 2000 11:29:24 -0500 From: Dan Nelson To: Evren Yurtesen Cc: freebsd-questions@FreeBSD.ORG Subject: Re: how to delete all files but the XYZ file. Message-ID: <20000826112924.A25714@dan.emsphone.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.3.7i In-Reply-To: ; from "Evren Yurtesen" on Sat Aug 26 11:25:00 GMT 2000 X-OS: FreeBSD 5.0-CURRENT Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In the last episode (Aug 26), Evren Yurtesen said: > Lets say I have 1230 files in one directory and I want to delete > all of the files but not the files named XYZ, XYA, XYB etc. > I want to do this from shell without using any file managers. (since > actually I need to do this from a script) You could do for i in * ; do case i in XY*) ;; *) echo $i ;; esac done | xargs rm , but that will print an error on directories (and not recurse into them). You could also try find . ! -name "XY*" | xargs rm , which will recurse into subdirs as well. -- Dan Nelson dnelson@emsphone.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message