ls -b should print the file names with non-printable characters, for example,
ex ex.txt should be shown as
ex\ ex.txt, but this does not work on macOS, it is still
ex ex.txt. Does anyone know the reason?
-b option isn't standardised, so its behaviour is implementation-dependent.
Many Linux systems use GNU ls by default; it defines the
-b option as
print C-style escapes for nongraphic characters
and uses an elaborate quoting implementation. The space character is a nongraphic character so it ends up being escaped.
On macOS the definition of
-b is different:
-B Force printing of non-printable characters (as defined by
ctype(3)and current locale settings) in file names as
\xxx, where xxx is the numeric value of the character in octal.
-b As -B, but use C escape codes whenever possible.
ctype functions (or macros) consider that the space character is printable, so it's not escaped.