From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5373 invoked by alias); 12 Feb 2014 05:13:21 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18424 Received: (qmail 21856 invoked from network); 12 Feb 2014 05:13:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140211211309.ZM24838@torch.brasslantern.com> Date: Tue, 11 Feb 2014 21:13:09 -0800 In-reply-to: Comments: In reply to Leonardo Barbosa "executing commands in directories containing specific files" (Feb 11, 10:11pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: executing commands in directories containing specific files MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 11, 10:11pm, Leonardo Barbosa wrote: } } I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say i } have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux, b.aux, } c.aux. What's the best way of doing that? I like using the (e) flag, but it's sometimes tricky to get right on the first try because you have to be careful to match up the parens in the reply=(...) assignment, the quotes around the expression, the outer set of delimiters (I used [...] below) and the parens around the whole thing: rm **/*.tex(.e['reply=(${REPLY:r}.aux)']) But you can also use colon-modifiers as glob qualifiers, so if the .tex never appears anywhere but at the end: rm **/*.tex(.:s/.tex/.aux) If you've already got the filenames, say, in an array: texi=( $(find $HOME -type f -name '*.tex') ) Colon-modifiers work on every word in an array, so you can use the "^" flag (rcexpandparam) like so: rm ${^texi:r}.aux Or you can just use one of the loops already suggested.