Why non-ASCII characters displayed as question-marks?

If non-ASCII characters (especially CJK characters) are displayed as question-marks as following:

???????????????????????????.pdf

In most cases, it’s caused by LC_CTYPE environment variable was not set properly.

To test if the problem caused by LC_CTYPE environment, run following command in ssh session in error:

export LC_CTYPE=en_US.UTF-8

Then try again the command that outputs question-marks, and if you are in luck, the correct characters should be displayed as you expected.

Once we confirm that the problem is caused by LC_CTYPE, the solution is simple. Just edit ~/.bash_profile file, and append a new line with export LC_CTYPE=en_US.UTF-8 command.

Then every time you login into the host, the LC_CTYPE variable will be set properly for you.