How to remove special character from a folder name?

I am creating a folder like

mkdir -p ../service/target/static

but windows creates it with some special character static. I need to explicitely remove that special character using shell script. I tried with rn and mv commands but doesn't seem to work and rename command giving error command not found.


Solution 1:

FWIW. Below is a simple script to rename a file(or directory).

> cat rename-file
#!/bin/bash
source=$1
target=`echo "$source" | sed -e 's/[^A-Za-z0-9._-]/_/g'`
if [ "$source" != "$target" ]; then
    mv "$source" "$target"
fi

For example (go to the directory, write the command and tab-expand the filename)

> ls -1
'a\b(c#d@e'
> rename-file a\\b\(c#d@e
> ls -1
a_b_c_d_e

You might want to fit the translation to your needs.

s/[^A-Za-z0-9._-]/_/g