John,

Here's a short little script that will do only what you
asked.  It works within a single directory and, as written,
will not descend a directory tree.  It will replace one
space or consecutive spaces in a file name with a single
underscore.  As you can see, you must supply the directory
name on the command line.  Any additional error checking is
left as an exercise for the reader.

BTW, I borrowed some from the aforementioned article in SW
Expert, so I give credit where it's due.

------
#!/bin/bash

if [ "$1" = "" ]; then
    echo ""
    echo "Usage: `basename $0` <dir>  or  `basename $0` .
(for current directory)"
    echo "Aborting..."
    echo ""
    exit 1
fi

save_dir=`pwd`
cd $1

find . -name "* *" -maxdepth 1 | while read name
do
  mv "$name" `echo "$name" | sed "s/[ ][ ]*/ /g" | sed "s/[
]/_/g"`
done

cd $save_dir
exit 0
--------

Cheers,
Ed

On Sat, 20 Jan 2001 23:39, John Aldrich wrote:
> 
> On Sat, 20 Jan 2001, Ed Alexander wrote:
> > There was an article in "Server/Workstation Expert"
> > magazine last October which explained in detail how 
> > to do exactly what you're asking.  Get the file:
> > 
> > http://swexpert.com/C2/SE.C2.OCT.00.pdf
> > 
> Ed... I know you're probably working on the old "give a
> man
> a fish and he'll eat for a day, teach a man to fish and
> he'll eat for life" theory. However, I got lost in that
> after the first page. I'll tell you this... the Directory
> names are legal *nix directory names -- no spaces. :-)
> Only the filenames 'cause they were designed with Windows 
> users in mind. :-)
>         John



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to