[CLUE-Tech] removing spaces from filenames?

Dale Hawkins dhawkins at cdrgts.com
Mon Nov 18 08:39:27 MST 2002


Dave Price <davep at kinaole.org> writes:

> Hi,
> 
> I have a _bunch_ of files that were created on a windoze system with
> embedded spaces in their names.  Can anyone recommend a technique to
> programmatically rename the files - replacing ' ' with '_' on both the
> file and dir names?

find, xargs, and sed should be able to do the trick.

I usually write a bash one-liner to feed xargs.

Something like:

--------------------8< (remove_spaces.sh) --------------------
#!/bin/bash

OLD_NAME="$1"
NEW_NAME=`echo $OLD_NAME | sed 's/ /_/g'`

echo mv "$OLD_NAME" "$NEW_NAME"

-------------------->8--------------------

Then on the command line:

$ find . -name " " | xargs -ifn remove_spaces.sh fn


Then again, the emacs directory browser, "dired", can do this sort of
thing as well (dired-do-rename-regexp).  Maybe some of the other file
browsers can do this as well?

-Dale

-- 
Now playing:
Jimmy Cliff - Struggling Man - (1) - Struggling Man

Better to have endured moments of sheer terror, than to have died having
lived life a coward.

A good solution now is better than a perfect solution tomorrow.
- From debian-curiosa

Payin' the bills with my mad programming skills.
- Weird Al



More information about the clue-tech mailing list