From owner-freebsd-questions@FreeBSD.ORG Wed Feb 4 15:48:17 2009 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 8E27A106566B for ; Wed, 4 Feb 2009 15:48:17 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id 4A62D8FC1A for ; Wed, 4 Feb 2009 15:48:17 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan-a.emsphone.com [199.67.51.107]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id n14FmG1R014939 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 4 Feb 2009 09:48:16 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.3/8.14.3) with ESMTP id n14FmG6B016696 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 4 Feb 2009 09:48:16 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.3/8.14.3/Submit) id n14FmES8016661; Wed, 4 Feb 2009 09:48:14 -0600 (CST) (envelope-from dan) Date: Wed, 4 Feb 2009 09:48:14 -0600 From: Dan Nelson To: t-u-t Message-ID: <20090204154814.GR75802@dan.emsphone.com> References: <332f78510902040635k6675a9b6u434879b42c66a579@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <332f78510902040635k6675a9b6u434879b42c66a579@mail.gmail.com> X-OS: FreeBSD 7.1-STABLE User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: ClamAV version 0.94.1, clamav-milter version 0.94.1 on email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Wed, 04 Feb 2009 09:48:16 -0600 (CST) X-Scanned-By: MIMEDefang 2.45 Cc: freebsd-questions@freebsd.org Subject: Re: shell commands - exclusion X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Feb 2009 15:48:17 -0000 In the last episode (Feb 04), t-u-t said: > hi, i don't know if this is a freak question, but i was looking around to > see if this is possible, and what the convention would be. > > if i have say one (or even two) single file/directories among many others, > and i want to perform any said function like cp, mv, rm, etc.. , to all > other files except that one or two, is there a way to do that in a single > command? > e.g > rm -r * {-except foo1 foo15} zsh has the ^ and ~ glob metacharacters that are enabled with you enable EXTENDED_GLOB: ^x (Requires EXTENDED_GLOB to be set.) Matches anything except the pattern x. This has a higher precedence than `/', so `^foo/bar' will search directories in `.' except `./foo' for a file named `bar'. x~y (Requires EXTENDED_GLOB to be set.) Match anything that matches the pattern x but does not match y. This has lower precedence than any operator except `|', so `*/*~foo/bar' will search for all files in all directories in `.' and then exclude `foo/bar' if there was such a match. Multiple patterns can be excluded by `foo~bar~baz'. In the exclusion pattern (y), `/' and `.' are not treated specially the way they usually are in globbing. > and if there is, could the same be applied to other similar batch (?) > operations, like pkg_delete -f "*" { except firefox3 wine thunderbird } > etc.. That wildcard is expanded internally by pkg_delete using the C fnmatch() function, which just does simple *?[] shell pattern matching. > i'm a bit new to the shell (took me a while to figure out *ls* and *ls | > more*), but i can't find anything from google cuz i don't know what this > would be called in the first place. > > otherwise is it better to protect them with chflags or other trickery? One workaround is to temporarily move the files you don't want to process into another directory, then move them back when you're done. -- Dan Nelson dnelson@allantgroup.com