[Linux-disciples] Troubles with 'rename'

Stephen R Laniel steve at laniels.org
Tue Jun 21 15:54:25 EDT 2005


On Sat, Apr 30, 2005 at 09:55:00AM -0400, Adam Rosi-Kessel wrote:
> I don't think rename can handle that kind of target:
> 
> # mkdir some\ dir
> # touch some\ dir/some\ file
> # ls some\ dir
> some file
> # rename "s/ /_/g" some\ dir/some\ file
> Can't rename some dir/some file some_dir/some_file: No such file or directory

I just ran into this again. My first guess is that 'rename'
won't allow you to rename a file if your renaming rule would
affect the file's parent directories as well. So

rename 's/ /_/g' some_dir/some\ file

would work fine, but

rename 's/ /_/g' some\ dir/some_file

does not.

It seems like the solution to this is to use the find
command, cd into the directory containing the file, rename
the file, then back out and rename the parent directory.
Something like this should do the trick, though some problem
or another with embedded spaces is making this particular
command fail:

for i in $(find -depth -iname '*\ *'); do cd $(dirname $i); rename 's/ /_/g' "$i"; done

Like I said, that's not quite working, but I suspect
something like that would work.

-- 
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: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20050621/4d7b39a8/attachment.pgp


More information about the Linux-disciples mailing list