Renaming Files on Hoary

Stephen R Laniel steve at laniels.org
Tue Jun 14 21:24:18 UTC 2005


On Tue, Jun 14, 2005 at 10:09:30PM +0100, Tony Arnold wrote:
> find . -name '*.JPG' -exec mv {} `cat {} | sed -e 's/\.JPG/.jpg/'` \;

I think you meant 'echo' where you wrote 'cat' above.

I'd simplify your script a little. First, the '-e' in sed is
superfluous. Second, bash contains a nice little feature to
take care of your 'sed' bit above; instead of

mv $i `echo $i |sed 's/foo/bar'`

you can do

mv $i ${i//foo/bar}

So I'd rewrite what you did as

for i in $(find . -name '*.JPG'); do
	mv $i ${i//.JPG/.jpg}
done

I like the '$(...)' syntax, because sometimes -- not often,
but sometimes -- I have embedded backticks, and I don't like
having to escape them; I think

$(cmd1 --arg1 $(cmd2) --arg2 $(cmd3))

looks better than

`cmd1 --arg1 \`cmd2\` --arg2 \`cmd3\``

But TMTOWTDI. Your method would work in more shells; this
one's tuned to bash.

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050614/eafa1259/attachment.pgp>


More information about the ubuntu-users mailing list