From owner-freebsd-questions Thu Mar 7 23:38:27 2002 Delivered-To: freebsd-questions@freebsd.org Received: from smtp05.retemail.es (smtp05.iddeo.es [62.81.186.15]) by hub.freebsd.org (Postfix) with ESMTP id 7089837B400 for ; Thu, 7 Mar 2002 23:38:24 -0800 (PST) Received: from conway.localdomain ([62.174.73.145]) by smtp05.retemail.es (InterMail vM.5.01.03.02 201-253-122-118-102-20010403) with SMTP id <20020308073822.OFGX1525.smtp05.retemail.es@conway.localdomain>; Fri, 8 Mar 2002 08:38:22 +0100 Date: Fri, 8 Mar 2002 08:41:14 +0100 From: F.Xavier Noria To: "Jon Larssen" Cc: freebsd-questions@FreeBSD.org Subject: Re: find(1) usage Message-Id: <20020308084114.4f110253.fxn@isoco.com> In-Reply-To: References: X-Mailer: Sylpheed version 0.7.2 (GTK+ 1.2.10; i386--freebsd4.4) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, 08 Mar 2002 05:56:02 +0000 "Jon Larssen" wrote: : Now, I'd like to use the -exec expression of find(1) to obtain the following : (sample) command: : : cp -p /etc/master.passwd backup/etc/master.passwd : : I know there's a thingy, {}, that would give the whole path : (backup/etc/master.passwd, for instance). Now, how can I erase the backup : part? Is this doable just with clever use of find(1)? Not clever, but seems to work :-): $ find backup/ -name '*' -exec \ perl -e '$cur = $bak = shift; $cur =~ s,[^/]*,,; system qq(cp -p "$cur", "$bak")' \ {} \; I prefer not to use -exec when it is not acting as a filter: $ find backup/ -name '*' | perl -ne \ '$cur = $bak = $_; $cur =~ s,[^/]*,,; system qq(cp -p "$cur", "$bak")' -- fxn To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message