Sunday, October 23, 2016

fixspace

#!/bin/sh

I=10

while [ $I -gt 1 ]; do

        rename " " _ *
        rename "(" _ *
        rename ")" _ *
        rename "'" _ *
    rename "&" _ *
    rename "[" _ *
    rename "]" _ *
    rename "?" _ *
    rename ":" _ *
    rename "!" _ *


        I=`expr $I - 1`

done
Version 2 - with recursion:

#!/bin/sh

I=10

while [ $I -gt 1 ]; do

find . -name "* *" -print -exec rename " " _ {} \;
find . -name "*&*" -print -exec rename "&" _ {} \;
find . -name "*(*" -print -exec rename "(" _ {} \;
find . -name "*)*" -print -exec rename ")" _ {} \;
find . -name "*'*" -print -exec rename "'" _ {} \;
find . -name "*[*" -print -exec rename "[" _ {} \;
find . -name "*]*" -print -exec rename "]" _ {} \;
find . -name "*:*" -print -exec rename ":" _ {} \;
find . -name "*|*" -print -exec rename "|" _ {} \;
find . -name "*%*" -print -exec rename "%" _ {} \;
find . -name "*\**" -print -exec rename "*" _ {} \;
find . -name "*\!*" -print -exec rename "!" _ {} \;
find . -name "*\?*" -print -exec rename "?" _ {} \;

        I=`expr $I - 1`

done

1 comment:

  1. The above will remove spaces and other annoying special characters in Linux file names.

    ReplyDelete