From owner-freebsd-questions@FreeBSD.ORG Tue Aug 31 17:03:50 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9BFDE16A4CE for ; Tue, 31 Aug 2004 17:03:50 +0000 (GMT) Received: from rwcrmhc13.comcast.net (rwcrmhc13.comcast.net [204.127.198.39]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7F15F43D49 for ; Tue, 31 Aug 2004 17:03:50 +0000 (GMT) (envelope-from fbsd-questions@trini0.org) Received: from hivemind.trini0.org (trini0.org[65.34.205.195]) by comcast.net (rwcrmhc13) with ESMTP id <2004083117002401500mhp50e>; Tue, 31 Aug 2004 17:03:50 +0000 Received: from [192.168.0.3] (gladiator.trini0.org [192.168.0.3]) by hivemind.trini0.org (Postfix) with ESMTP id 33B941A3; Tue, 31 Aug 2004 13:00:23 -0400 (EDT) Message-ID: <4134AEAB.8090805@trini0.org> Date: Tue, 31 Aug 2004 13:00:27 -0400 From: Gerard Samuel User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040812) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Giorgos Keramidas References: <413495FD.10700@trini0.org> <20040831153725.GA53122@orion.daedalusnetworks.priv> In-Reply-To: <20040831153725.GA53122@orion.daedalusnetworks.priv> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: Renaming files using find X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Aug 2004 17:03:50 -0000 Giorgos Keramidas wrote: > On 2004-08-31 11:15, Gerard Samuel wrote: > >>Im trying to rename a few files with the .dist extension. >>Im trying -> >>hivemind# find . -name '*.dist' -exec cp {} `basename {} .dist` \; >> >>And Im getting -> >>cp: ./html.php.dist and ./html.php.dist are identical (not copied). >>cp: ./horde.php.dist and ./horde.php.dist are identical (not copied). >>cp: ./motd.php.dist and ./motd.php.dist are identical (not copied). >>cp: ./mime_mapping.php.dist and ./mime_mapping.php.dist are identical (not copied). >>cp: ./prefs.php.dist and ./prefs.php.dist are identical (not copied). >>cp: ./registry.php.dist and ./registry.php.dist are identical (not copied). >>cp: ./lang.php.dist and ./lang.php.dist are identical (not copied). >>cp: ./mime_drivers.php.dist and ./mime_drivers.php.dist are identical (not copied). >> >>What is wrong with the command that I issued. > > > The basename command gets expanded by the shell you use *BEFORE* find > has a change to run. > > You can try playing tricks with escaping the backquotes, which is > probably going to result very quickly in ugliness like \\\`foo\\\` or > you can use find to "generate" a list of filenames which will be > "processed" by the rest of the command-line to spit out the rename > commands, and feed them to sh(1) for execution, i.e.: > > $ ls -l > total 0 > -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 koko.dist > -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 lala.dist > > $ find . -name \*.dist | \ > awk '{ printf "mv \"%s\" `basename \"%s\" .dist`\n",$0,$0; }' > > mv "./lala.dist" `basename "./lala.dist" .dist` > mv "./koko.dist" `basename "./koko.dist" .dist` > > $ find . -name \*.dist | \ > awk '{ printf "mv \"%s\" `basename \"%s\" .dist`\n",$0,$0; }' | sh > > $ ls -l > total 0 > -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 koko > -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 lala > Thanks for the explanation...