Wednesday, October 20, 2010

Replacing white spaces (' ') with underscores ('_')

You've got plenty of files with spaces on its name and you wanna replace them with underscores?
Check this:

for i in *;do TARGET=`echo $i | sed 's/\ /_/g'`; mv "$i" $TARGET;done

In my case, these were rar files which I then wanted to uncompress:

for i in *;do unrar x "$i" ;done

Bash is really usefull, ain't that right?

No comments: