Pablo Gosse Pablo Gosse - 1 year ago 66
Linux Question

How to rename a folder that contains smart quotes

I have a folder that was created automatically. The user unintentionally provided smart (curly) quotes as part of the name, and the process that sanitizes the inputs did not catch these. As a result, the folder name contains the smart quotes. For example:


I'm now trying to rename/remove said folder on the command line, and none of the standard tricks for dealing with files/folders with special characters (enclosing in quotes, escaping the characters, trying to rename it by inode, etc.) are working. All result in:

mv: cannot move this-is-my-folder’s-name-“Bob” to this-is-my-folders-name-BOB: No such file or directory

Can anyone provide some advice as to how I can achieve this?

Answer Source

To get the name in a format you can copy-and-paste into your shell:

printf '%q\n' this*

...will print out the filename in a manner the shell will accept as valid input. This might look something like:


...which you can then use as an argument to mv:

mv $'this-is-my-folder200\231s-name-200\234Bob200\235' this-is-my-folders-name-BOB

Incidentally, if your operating system works the same way mine does (when running the test above), this would explain why using single-character globs such as ? for those characters didn't work: They're actually more than one byte long each!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download