Skip to content

Terminal can't render letters/characters that not English (or it can?)?

It's not really that it can't show them, for example: Chinese characters. When I type a Chinese character using ibus, it shows it very well. But when a file have a Chinese name, it can't show this name, it shows blank or long string of numbers with /\"", something like that.

For example, if I open the terminal, change ibus to Chinese and type, I got something like this:

[user@mypc ~]$ 你 好

But if there's a file name 你 好.doc and I use ls command to list it or use ranger to navigate the file, it will show like this:

[user@mypc ~]$ ls
file.txt    "       .doc"

or sometime like this (I guess it depends on specific characters):

[user@mypc ~]$ ls
file.txt   "123/60/4646/"4875/'.doc" (<--I made it up but it kind of look like this)

While I expect to see:

[user@mypc ~]$ ls
file.txt    "你 好.doc"

I've already put a Chinese font to /usr/local/share/fonts. I also un-comment zh_cn in locale. Only in terminal it behaves like this. If I use a GUI file manager, it looks fine.

0 points7 comments
Open on Reddit
About this post
Posted
Archived
Score
0 · 50% up
Kind
Text
ID
v98acy

Author

163
posts
618
comments
21
media
View profile

8 comments

Are you using a utf8 locale? What does locale output?

try doing LC_ALL=en_US.UTF-8 ls assuming en_US.UTF-8 is generated it with locale-gen. You could use any UTF-8 locale probably.

If it fails, try using a different terminal emulator. Also, arch wiki: https://wiki.archlinux.org/title/Locale#Troubleshooting

2 points

I try LC_ALL=en_US.UTF-8 ls and it does work. But my locale -a output already have en_US.utf8. I don't understand?

1 points

https://www.ibm.com/docs/en/aix/7.1?topic=locales-understanding-locale-environment-variables

The LC_CTYPE category determines character handling rules governing the interpretation of sequences of bytes of text data characters (that is, single-byte versus multibyte characters).

utf-8 which is used in linux is a variable length sequence, it ranges from 1 byte to 4 bytes for a character. You need to set an utf-8 encoding for the locale variables.

If you didn't set LANG, do that first. And then try setting LC_CTYPE

You need to put

LANG="en_US.UTF-8"

and maybe

LC_CTYPE="en_US.UTF-8"

in one of these files.

"$XDG_CONFIG_HOME/locale.conf"
"$HOME/.config/locale.conf"
/etc/locale.conf

Note: The files are source in that order and if the first file is found the next ones will NOT be sourced. So maybe put it somewhere in your ~/.bashrc or ~/.zshrc or ~/.profile and make sure to export the variables.

And LC_ALL should only be used as a last resort because it overrides all the other variables.

2 points
unknown author1 hidden

Deleted before we saved it.

1 points

No. ls doesn't really operate on individual bytes besides maybe for sorting so the worst you might get is a weirdly sorted list. More importantly ls doesn't need to modify the actual filename and has no reason to display it differently.

A lot of programs don't have to care about the distinction between utf8 and ascii like echo, head and even diff.

3 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.