Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On our CMS that went through many versions and hosting platforms, we just came across an accented image file that would not work from it's url. So I ssh'd onto the box and tried to rename it.

However, I could not figure out how to type in it's name correctly. For instance, I know that if a file is called my file.txt you would do something like mv my\ file.txt my_new_file.txt but how do you move a file called café.txt?

In the end, I used a wildcard and did mv caf*.txt cafe.txt but I'm still wondering why this accented image would not work in the first place, and what would have been the proper way to handle it on unix.

share|improve this question
What terminal were you using ? The terminal is responsible for handling the encoding, the issue might stem from the terminal temporarily falling back to a different encoding, hiding the true nature of the error to you. – b0fh Aug 4 '15 at 9:18
up vote 4 down vote accepted

Using bash:

Just to see my files:

$ ls

Check the hex bytes of the file name (note: mine may be different... mine are probably UTF-8 encoded):

$ echo * | hexdump -C
00000000  63 61 66 c3 a9 2e 74 78  74 0a                    |caf...txt.|

Then craft a file name using the hex codes for the parts that aren't found on your keyboard:

$ ls $'caf\xc3\xa9.txt'

In bash, $' ... ' will expand escapes (much like "echo -e" does). And \x followed by a 2 digit hex code will replace it with that character.

And I don't see anything wrong with an:

ls caf*.txt

followed by a

mv caf*.txt cafe.txt

But if for some reason that would match multiple files, you can use the hex stuff:

ls $'caf\xc3\xa9.txt'
mv $'caf\xc3\xa9.txt' café.txt
share|improve this answer

Unix filesystems store filenames as raw sequence of bytes. The kernel doesn't know or cares about what the names really are.

It is up to the applications accessing them to use the proper encoding to display non ASCII characters properly. The usual way is through the LC_ALL/LC_* or LANG environment variables. I would recommend to use an UTF-8 locale on all applications accessing the file system to avoid incompatibilities/inconsistencies.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.