From: Glynn Clements Subject: Re: shell/Perl question Date: Tue, 2 Nov 2004 06:58:21 +0000 Message-ID: <16775.12301.890251.209157@cerise.gclements.plus.com> References: Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-admin-owner@vger.kernel.org List-Id: Content-Type: text/plain; charset="us-ascii" To: vick Julius Cc: linux-admin@vger.kernel.org vick Julius wrote: > I have several directories (around 10) named ABC, DEF, GHI,... > Each directory contains more than 50 files named, for example, 1.jpg, 2.jpg, > 3.jpg,...50.jpg > These names are the same in each directory (this is what digital cameras do, > they give the same names...) > My problem is: I want to put all these files in the same directory, for > example, Photos, with the following names: > 1ABC.jpg, 2ABC.jpg, ...50ABC.jpg, 1DEF.jpg, 2DEF.jpg...50DEF.jpg,... > each image filename (such as 1.jpg) will be split and to insert the name of > the directory (such as ABC..) after the first part of the name and finally > append the extension (.jpg) to the filename. Two examples: for dir in ABC DEF GHI ; do for file in `(cd "$dir" && echo *.jpg)` ; do mv "$dir/$file" "Photos/${file%%.jpg}$dir.jpg" done done find . -type f | sed 's!^\./\(.*\)/\(.*\)\.jpg$!mv \1/\2.jpg Photos/\2\1.jpg!' | sh If any of the filenames contain spaces, it gets more complex. -- Glynn Clements