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.

  • You said "but windows creates it...", well if your running Windows... then this is not the appropriate place for your question. That said, you should always use quotes, single or doubles as appropriate, to avoid any problems. e.g.: mkdir -p '../service/target/static' Mar 14, 2019 at 13:32
  • Doesn't seem to work with quotes. Mar 14, 2019 at 14:18
  • 1
    Is the mkdir command in a shell script? If so, the script might have DOS/Windows-style line endings, which include a carriage return character that the unix shell will treat as part of the command line (and in this case, part of the filename). See this stackoverflow question. Mar 14, 2019 at 20:28
  • dos2unix worked for me. Mar 14, 2019 at 21:16
  • So you are saying mv static? staticx would not change the special character to the letter x? Mar 14, 2019 at 21:53

1 Answer 1


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

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

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

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

You might want to fit the translation to your needs.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .