coolboarderguy
October 17th, 2007, 05:39 AM
Hi All,
I'm trying to replace the space in file names with an underscore. Someone suggested using tr with ls -Q then piping to mv as below
for i in $(ls -Q); do mv $i $(echo $i | tr ' ' '_');done
bu it gives the following,
mv: cannot stat `"file': No such file or directory
mv: cannot stat `1"': No such file or directory
mv: cannot stat `"file': No such file or directory
mv: cannot stat `2"': No such file or directory
mv: cannot stat `"file': No such file or directory
mv: cannot stat `3"': No such file or directory
mv: cannot stat `"file': No such file or directory
mv: cannot stat `4"': No such file or directory
Why is it looking for the file name separately? A little confused here.
for i in $(ls -Q);do echo $i ;done
"file
1"
"file
2"
"file
3"
"file
4"
I'm trying to replace the space in file names with an underscore. Someone suggested using tr with ls -Q then piping to mv as below
for i in $(ls -Q); do mv $i $(echo $i | tr ' ' '_');done
bu it gives the following,
mv: cannot stat `"file': No such file or directory
mv: cannot stat `1"': No such file or directory
mv: cannot stat `"file': No such file or directory
mv: cannot stat `2"': No such file or directory
mv: cannot stat `"file': No such file or directory
mv: cannot stat `3"': No such file or directory
mv: cannot stat `"file': No such file or directory
mv: cannot stat `4"': No such file or directory
Why is it looking for the file name separately? A little confused here.
for i in $(ls -Q);do echo $i ;done
"file
1"
"file
2"
"file
3"
"file
4"