August Feng

creating files in linux that contains non utf-8 characters

About

The Rust std library implements OsString, but it doesn't translate directly to String because file names on operating systems can be non utf-8-encoded.

Linux

On linux, we can create a non utf-8-encoded string like this.

  printf "hello_\x80_world" | xargs touch
  ls -l hello_\200_world
  # -rw-r--r-- 1 root root 0 Sep 21 01:49 'hello_'$'\200''_world

MacOS

On macOS, the command above would fail because the OS does not allow non UTF-8 encoded filenames.

  ls -l hello_\200_world
  # -rw-r--r-- 1 root root 0 Sep 21 01:49 'hello_'$'\200''_world'

Windows

Meh.