sábado, 28 de julio de 2012

Remove spaces from several filenames

I need to make a backup in a linux server of several files created by MS Windows system. This files has spaces in the filename.  As a linux doesn't like spaces in the filenames I decided to change those filenames to another that has a underscore replacing the spaces.

Here we go:

We go to the directory were have the files to change and execute this comand:

for a in * ; do b=`echo $a |sed 's/ /_/g'` ; echo "$a" " ---> ""$b" ; mv -f "$a" "$b" ;done

The command doesn't change the files that hasn't spaces, it gives as
mv: 'fileswithoutspace' and 'fileswithoutspace' are the same file

So don't worry about that.





No hay comentarios:

Publicar un comentario