From owner-freebsd-questions@FreeBSD.ORG Sat Jan 5 11:13:01 2008 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 76A4B16A480 for ; Sat, 5 Jan 2008 11:13:01 +0000 (UTC) (envelope-from michel@lpthe.jussieu.fr) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by mx1.freebsd.org (Postfix) with ESMTP id 2629B13C45B for ; Sat, 5 Jan 2008 11:13:00 +0000 (UTC) (envelope-from michel@lpthe.jussieu.fr) Received: from parthe.lpthe.jussieu.fr (parthe.lpthe.jussieu.fr [134.157.10.1]) by shiva.jussieu.fr (8.13.8/jtpda-5.4) with ESMTP id m05BCxjD025736 for ; Sat, 5 Jan 2008 12:12:59 +0100 (CET) X-Ids: 165 Received: from niobe.lpthe.jussieu.fr (niobe.lpthe.jussieu.fr [134.157.10.41]) by parthe.lpthe.jussieu.fr (Postfix) with ESMTP id 45B2723724E for ; Sat, 5 Jan 2008 12:12:58 +0100 (CET) Received: by niobe.lpthe.jussieu.fr (Postfix, from userid 2005) id 346988F; Sat, 5 Jan 2008 12:12:58 +0100 (CET) Date: Sat, 5 Jan 2008 12:12:58 +0100 From: Michel Talon To: freebsd-questions@freebsd.org Message-ID: <20080105111258.GA4180@lpthe.jussieu.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (shiva.jussieu.fr [134.157.0.165]); Sat, 05 Jan 2008 12:12:59 +0100 (CET) X-Virus-Scanned: ClamAV 0.92/5368/Sat Jan 5 01:35:28 2008 on shiva.jussieu.fr X-Virus-Status: Clean X-Miltered: at shiva.jussieu.fr with ID 477F663B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! Subject: Re: batch rename 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: Sat, 05 Jan 2008 11:13:01 -0000 Aryeh M. Friedman wrote: > My goal is to rename several files in such a way as to decapitalize > > starting letters in their names. The solution seems to be simple > > but I'm stuck. What should I use? awk/sed or write some > > shell-script? > > This assumes tcsh: > > foreach i (`ls [A-Z][a-z]*`) > mv $i `echo $i|tr 'A-Z' 'a-z'` > end This will disfunction if the names have embedded white spaces. I happen to batch rename songs etc. which almost invariably have white spaces and other horrors. So i use something like mv "$i" `echo $i|sed -e 's/ */_/g' -e '.....' ` Sed has the advantage you can do several transformations at one stroke, and fine tune the transformations. Double quotes avoid that the shell breaks names on white space. -- Michel TALON