[Linux-disciples] Troubles with 'rename'

Stephen R Laniel steve at laniels.org
Sat Apr 30 09:36:42 EDT 2005


Imagine I have a hierarchy of directories and files, some of
whose names contain spaces. I'd like to rename all of them,
replacing spaces with underscores. This approach to doing so
doesn't seem to work:

find . -depth -iname '* *' -exec rename 's/ /_/g' '{}' \;

Nor does substituting xargs in the appropriate place. In
either case I get

Can't rename ./Shannon Wright/Perishables Goods/Shannon Wright---Perishables Goods---05---familiar settings.ogg ./Shannon_Wright/Perishables_Goods/Shannon_Wright---Perishables_Goods---05---familiar_settings.ogg: No such file or directory

I assume the trouble is that the directory is getting
renamed before the file contained within it. So let's say I
have a file

'space dir1/file 1'

If 'space dir1' gets renamed to 'space_dir1', and 'find'
moves on to 'space dir1/file 1', it'll find that the latter
doesn't exist.

But I thought that's what the '-depth' argument to 'find'
was supposed to solve.

Does anyone know how to fix this problem?

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/


More information about the Linux-disciples mailing list