Home  >  Article  >  System Tutorial  >  Teach you how to change the font on the Linux console

Teach you how to change the font on the Linux console

WBOY
WBOYOriginal
2024-06-02 17:16:59997browse

Teach you how to change the font on the Linux console

I try to keep my mind as peaceful as possible, but there are always some things that make me uncomfortable, such as the console font is too small. Mark my words, friend, one day your eyes will degenerate and you will no longer be able to see those tiny fonts you use when coding, and then you will regret it.

Fortunately, Linux diehards, you can change the console font. According to Linux's usual habit, the ever-changing Linux environment makes this problem less simple and clear, and there is no such thing as font management on Linux, which makes it easy for us to get confused. In this article, I'm going to show you the easiest way I've found to change fonts.

What the hell is the Linux console?

First let us clarify what we are talking about. When I mention Linux consoles, I'm referring to TTY1-6, the virtual terminals you switch to from a graphical environment with Ctrl-Alt-F1 to F6. Pressing Ctrl Alt F7 will switch back to the graphics environment. (However, these hotkeys are no longer universal, and your Linux distribution may have different key mappings. Your number of TTYs may also be different, and your graphical environment session may not be F7. For example, Fedora's default graphical session is F2, It only has an extra terminal in F1.) I think it's really cool to be able to have both an X session and a terminal session.

The Linux console is part of the kernel and does not run within an X session. It's the same console you use in a headless server without a graphical environment. I call the X terminal in a graphical session a terminal, and I refer to the console and X terminal collectively as a terminal emulator.

But it’s not over yet. The Linux terminal has come a long way from the early ANSI days and now has Unicode support and some limited support for graphics thanks to the Linux framebuffer. And there are many multimedia applications running under the console, which we will mention in future articles.

Console screenshot

The easiest way to get a console screenshot is to run the console inside the virtual machine. You can then capture it using your favorite screenshot software on the host system. But with fbcat and fbgrab you can also take screenshots directly on the console. fbcat creates an image in Portable Pixel Map Format (PPM); this is a highly portable uncompressed image format that can be read on all operating systems, and of course you can convert it to any other you like Format. fbgrab is a wrapper script of fbcat, used to generate a PNG file. Many people have written multiple versions of fbgrab. Each version has limited options and can only create full screen captures.

The execution of fbcat requires root privileges, and its output needs to be redirected to a file. You don’t need to specify a file extension, just enter the file name:

$ sudo fbcat > Pictures/myfile

After cropping in GIMP, you get the picture below.
Teach you how to change the font on the Linux console

It would be nice if there was a little padding in the left margin. If any readers know how to achieve it, please tell me in the message box.

fbgrab also has some options, which you can view through man fbgrab. These options include taking a screenshot of another console, and taking a delayed screenshot. As you can see in the example below, fbgrab screenshots are similar to fbcat screenshots, except that you don’t need to explicitly recharacterize the output:

$ sudo fbgrab Pictures/myOtherfile
Find font

As far as I know, there is no other way than looking at the font storage directory /usr/share/consolefonts/ (Debian, etc.), /lib/kbd/consolefonts/ (Fedora), /usr/share/kbd/consolefonts (openSUSE) Method to list installed fonts.

Change font

可读字体不是什么新概念。我们应该尊重以前的经验!可读性是很重要的。可配置性也很重要,然而现如今却不怎么看重了。

在 Debian/Ubuntu 等系统上,可以运行 sudo dpkg-reconfigure console-setup 来设置控制台字体,然后在控制台运行 setupcon 命令来让变更生效。setupcon 属于 console-setup 软件包中的一部分。若你的 Linux 发行版中不包含该工具,可以在 openSUSE 中下载到它。

你也可以直接编辑 /etc/default/console-setup 文件。下面这个例子中设置字体为 32 点大小的 Terminus Bold 字体,这是我的最爱,并且严格限制控制台宽度为 80 列。

ACTIVE_CONSOLES="/dev/tty[1-6]"
CHARMAP="UTF-8"
CODESET="guess"
FONTFACE="TerminusBold"
FONTSIZE="16x32"
SCREEN_WIDTH="80"

这里的 FONTFACE 和 FONTSIZE 的值来自于字体的文件名 TerminusBold32x16.psf.gz。是的,你需要反转 FONTSIZE 中值的顺序。计算机就是这么搞笑。然后再运行 setupcon 来让新配置生效。可以使用 showconsolefont 来查看当前所用字体的所有字符集。要查看完整的选项说明请参考 man console-setup。

Systemd

Systemd 与 console-setup 不太一样,除了字体之外,你无需安装任何东西。你只需要编辑 /etc/vconsole.conf 然后重启就行了。我在 Fedora 和 openSUSE 系统中安装了一些额外的大字号的 Terminus 字体包,因为默认安装的字体最大只有 16 点而我想要的是 32 点。然后将 /etc/vconsole.conf 的内容修改为:

KEYMAP="us"
FONT="ter-v32b"

The above is the detailed content of Teach you how to change the font on the Linux console. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn