Linux консоль utf 8

How to get terminal’s Character Encoding

Now I change my gnome-terminal’s character encoding to «GBK» (default it is UTF-8), but how can I get the value(character encoding) in my Linux?

7 Answers 7

The terminal uses environment variables to determine which character set to use, therefore you can determine it by looking at those variables:

These environment variables are used by applications that are using the terminal for I/O. The terminal emulator itself has no knowledge of them whatsoever, and its currently effective character encoding is a setting somewhere within the emulator program (a data member inside a libvte class in the case of GNOME Terminal).

the ordering of variables suggested here is not good. a more complete solution would be something like: echo $>>. then again, the variable being set isn’t a guarantee that they’re valid, so you should stick to the locale program (as seen in other answers here).

As @JdeBP said, the terminal does not use the locale environment variables to determine its encoding. The terminal can however let applications that interact it know its encoding by setting the locale environment variables. For instance, on macOS you can choose the terminal encoding and optionally set the locale environment variables at terminal startup in Terminal > Preferences > Profiles > Advanced .

locale command with no arguments will print the values of all of the relevant environment variables except for LANGUAGE.

This is what worked for me on a CentOS system. It showed the system encoding based upon current language settings. The terminal settings used to get to that machine are a different story and a function of the client being used.

Check encoding and language:

$ echo $LC_CTYPE ISO-8859-1 $ echo $LANG pt_BR 
$ export LC_ALL=pt_PT.utf8 $ export LANG="$LC_ALL" 
python -c "import sys; print(sys.stdout.encoding)" 

Circumstantial indications from $LC_CTYPE , locale and such might seem alluring, but these are completely separated from the encoding the terminal application (actually an emulator) happens to be using when displaying characters on the screen.

They only way to detect encoding for sure is to output something only present in the encoding, e.g. ä , take a screenshot, analyze that image and check if the output character is correct.

So no, it’s not possible, sadly.

To see the current locale information use locale command. Below is an example on RHEL 7.8

[usr@host ~]$ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= 

Examination of https://invisible-island.net/xterm/ctlseqs/ctlseqs.html, the xterm control character documentation, shows that it follows the ISO 2022 standard for character set switching. In particular ESC % G selects UTF-8. So to force the terminal to use UTF-8, this command would need to be sent. I find no way of querying which character set is currently in use, but there are ways of discovering if the terminal supports national replacement character sets.

Читайте также:  What is squid proxy in linux

However, from charsets(7), it doesn’t look like GBK (or GB2312) is an encoding supported by ISO 2022 and xterm doesn’t support it natively. So your best bet might be to use iconv to convert to UTF-8.

Further reading shows that a (significant) subset of GBK is EUC, which is a ISO2022 code, so ISO2022 capable terminals may be able to display GBK natively after all, but I can’t find any mention of activating this programmatically, so the terminal’s user interface would be the only recourse.

Источник

Linux console

The Linux console is a system console internal to the Linux kernel. The Linux console provides a way for the kernel and other processes to send text output to the user, and to receive text input from the user. The user typically enters text with a computer keyboard and reads the output text on a computer monitor. The Linux kernel supports virtual consoles — consoles that are logically separate, but which access the same physical keyboard and display.

This article describes the basics of the Linux console and how to configure the font display. Keyboard configuration is described in the /Keyboard configuration subpage.

Implementation

This article or section needs expansion.

Reason: In what ways is the Linux console limited compared to terminal emulators? (Discuss in Talk:Linux console)

The console, unlike most services that interact directly with users, is implemented in the kernel. This contrasts with terminal emulation software, such as Xterm, which is implemented in user space as a normal application. The console has always been part of released Linux kernels, but has undergone changes in its history, most notably the transition to using the framebuffer and support for Unicode.

Despite many improvements in the console, its full backward compatibility with legacy hardware means it is limited compared to a graphical terminal emulator.

Virtual consoles

The console is presented to the user as a series of virtual consoles. These give the impression that several independent terminals are running concurrently; each virtual console can be logged in with different users, run its own shell and have its own font settings. The virtual consoles each use a device /dev/ttyX , and you can switch between them by pressing Alt+Fx (where x is equal to the virtual console number, beginning with 1). The device /dev/console is automatically mapped to the active virtual console.

Text mode

Since Linux originally began as a kernel for PC hardware, the console was developed using standard IBM CGA/EGA/VGA graphics, which all PCs supported at the time. The graphics operated in VGA text mode, which provides a simple 80×25 character display with 16 colours. This legacy mode is similar to the capabilities of dedicated text terminals, such as the DEC VT100 series. It is still possible to boot in text mode (with vga=0 nomodeset ) if the system hardware supports it, but almost all modern distributions (including Arch Linux) use the framebuffer console instead.

Framebuffer console

As Linux was ported to other non-PC architectures, a better solution was required, since other architectures do not use VGA-compatible graphics adapters, and may not support text modes at all. The framebuffer console was implemented to provide a standard console across all platforms, and so presents the same VGA-style interface regardless of the underlying graphics hardware. As such, the Linux console is not a terminal emulator, but a terminal in its own right. It uses the terminal type linux , and is largely compatible with VT100.

Читайте также:  Kali linux x64 iso

Keyboard shortcuts

Keyboard Shortcut Description
Ctrl+Alt+Del Reboots the system (specified by the symlink /usr/lib/systemd/system/ctrl-alt-del.target )
Alt+F1 , F2 , F3 , . Switch to n-th virtual console
Alt+Left Switch to previous virtual console
Alt+Right Switch to next virtual console
Scroll Lock When Scroll Lock is activated, input/output is locked
Ctrl+c Kills current task
Ctrl+d Inserts an EOF
Ctrl+z Pauses current Task

Fonts

Note: This section is about the Linux console. For alternative console solutions offering more features (full Unicode fonts, modern graphics adapters etc.), see KMSCON or similar projects.

The Linux console uses UTF-8 encoding by default, but because the standard VGA-compatible framebuffer is used, a console font is limited to either a standard 256, or 512 glyphs. If the font has more than 256 glyphs, the number of colours is reduced from 16 to 8. In order to assign correct symbol to be displayed to the given Unicode value, a special translation map, often called unimap, is needed. Nowadays, most of the console fonts have the unimap built-in; historically, it had to be loaded separately.

By default, the virtual console uses the kernel built-in font with a CP437 character set[1], but this can be easily changed. The kernel offers about 15 built in fonts to choose from, from which the officially supported kernels provide two: VGA 8×16 font ( CONFIG_FONT_8x16 ) and Terminus 16×32 font ( CONFIG_FONT_TER16x32 ). The kernel chooses the one to use based on its evaluation of the screen resolution. Another builtin font can be forced upon by kernel parameters boot parameter setting such as fbcon=font:TER16x32 .

The kbd package provides tools to override the kernel decision for virtual console font and font mapping. Available fonts are provided in the /usr/share/kbd/consolefonts/ directory; those ending with .psfu or .psfu.gz have a Unicode translation map built-in.

Keymaps, the connection between the key pressed and the character used by the computer, are found in the subdirectories of /usr/share/kbd/keymaps/ ; see /Keyboard configuration for details.

Note: Replacing the font can cause issues with programs that expect a standard VGA-style font, such as those using line drawing graphics.

Tip: For European based languages written in Latin/Greek letters, you can use the eurlatgr font. It includes a broad range of Latin/Greek letter variations as well as special characters [2].

Preview and temporary changes

shows a table of glyphs or letters of a font.

setfont temporarily change the font if passed a font name (in /usr/share/kbd/consolefonts/ ) such as

Font names are case-sensitive. With no parameter, setfont returns the console to the default font.

So to have a small 8×8 font, with that font installed like seen below, use e.g.:

$ setfont -h8 /usr/share/kbd/consolefonts/drdos8x8.psfu.gz

To have a bigger font, the Terminus font ( terminus-font ) is available in many sizes, such as ter-132b which is large.

Читайте также:  Cache yandex browser linux

Note: setfont only works on the console currently being used. Any other consoles, active or inactive, remain unaffected.

Persistent configuration

The FONT variable in /etc/vconsole.conf is used to set the font at boot, persistently for all consoles. See vconsole.conf(5) for details.

For displaying characters such as Č, ž, đ, š or Ł, ę, ą, ś using the font lat2-16.psfu.gz :

It means that second part of ISO/IEC 8859 characters are used with size 16. You can change font size using other values (e.g. lat2-08 ). For the regions determined by 8859 specification, look at the Wikipedia:ISO/IEC 8859#The parts of ISO/IEC 8859.

Since mkinitcpio v33, the font specified in /etc/vconsole.conf gets automatically loaded during early userspace by default via the consolefont hook, which adds the font to the initramfs. See Mkinitcpio#HOOKS for more information.

You may also need to restart systemd-vconsole-setup.service after changing /etc/vconsole.conf .

If the fonts appear to not change on boot, or change only temporarily, it is most likely that they got reset when graphics driver was initialized and console was switched to framebuffer. By default, all in-tree kernel drivers are loaded early, NVIDIA users should see NVIDIA#Early loading to load their graphics driver before /etc/vconsole.conf is applied.

HiDPI

Audible tones

See also

Источник

How can I enable UTF-8 support in the Linux console?

enter image description here

Right now, it looks like this:

it’s a real 80×25 textmode terminal, so you can’t use more than 256 characters. Use framebuffer console if you want real utf-8.

3 Answers 3

Check that you have the locales package installed

you can navigate that list with the up/down arrow keys, for example choose en_US-UTF-8

edit your .bashrc by adding the following lines:

export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8 

Run the locale command ,the output should be similar to this::

LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= 

I do have the package installed — I think it comes by default with Debian Wheezy. It’s just that the console wasn’t in UTF-8 mode.

Sure (it’s limited on the number of glyphs, but it seems your locale is using UTF-8 encoding).

#!/bin/sh # send character-string to enable UTF-8 mode if test ".$1" = ".off" ; then printf '\033%%@' else printf '\033%%G' fi 

and (calling it «utf8»), «utf8 on» turns the encoding on.

Using the example given with pstree , here is an example after running the script (before, the same sort of output as in the question):

screenshot after

As noted in a comment, there’s a script unicode_start which does more, but all that is needed to address the question posed is the small script used as an example.

Addressing a different comment: At least on my system (and in the screenshot shown in the question), all of the characters used by pstree are supplied in the 512-glyph font used by default for Unicode support in the Linux console.

Источник

Оцените статью
Adblock
detector