IUBio

Spaces in Unix file names

Tim Cutts tjrc1 at mole.bio.cam.ac.uk
Thu Oct 2 03:31:08 EST 1997


In article <6kau06.rd.ln at wpxx02.toxi.uni-wuerzburg.de>,
Cornelius Krasel <krasel at wpxx02.toxi.uni-wuerzburg.de> wrote:

>To change filenames with spaces into filenames without spaces, do
>something like the following (should work for a bash-like shell):
>
>for i in *\ *
>do
>   new=`echo $i|tr -d ' '`
>   mv $i $new
>done
>
>This will rename all files "with space" in your current directory in
>"withspace". If "withspace" exists, it will be overwritten.

Since you are using GCG, you probably want a csh eequivalent for this,
and you probably don't want it to overwrite existing files, in which
case you want the following:

set noclobber
foreach f (*\ *)
  mv $f `echo $f | tr -d ' '`
end

If you want the spaces changed to underscores, rather than removed,
change

tr -d ' '

to

tr ' ' '_'

Tim.



More information about the Info-gcg mailing list

Send comments to us at biosci-help [At] net.bio.net