LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   replacing space in filenames (http://www.linuxquestions.org/questions/linux-general-1/replacing-space-in-filenames-73686/)

rooster13 07-17-2003 07:57 PM

replacing space in filenames
 
is there any way to replace spaces in filenames with, for example, '_'?? I have a whole bunch of files that origin from the windows world, and my bash scripts aren't working well with the "space" characters in filenames. Thanks for your time.

linuxlah 07-17-2003 08:17 PM

try this bash script

PHP Code:

for i in *; do mv "$i" `echo $i | tr ' ' '_'`; done 


rooster13 07-18-2003 05:35 AM

So, since I'm such a rookie with these bash scripts, I have to ask if this script would do the work (replace all spaces in directory and file names with '_' in all subdirs of the directory it runned from)

#!/bin/bash

ROOTDIR=$(pwd)
DIRS=$(find . -type d)
for d in $DIRS; do
cd $d
for i in *; do mv "$i" `echo $i | tr ' ' '_'`; done
cd $ROOTDIR
done


All times are GMT -5. The time now is 11:47 AM.