定制你的 Linux 终端外观的 5 项调整
终端
![](/data/attachment/album/202103/06/232911eg4g65gp4g2ww24u.jpg)


终端仿真器（或简称终端）是任何 Linux 发行版中不可或缺的一部分。


当你改变发行版的主题时，往往终端也会自动得到改造。但这并不意味着你不能进一步定制终端。


事实上，很多读者都问过我们，为什么我们截图或视频中的终端看起来那么酷，我们用的是什么字体等等。


为了回答这个经常被问到的问题，我将向你展示一些简单或复杂的调整来改变终端的外观。你可以在下图中对比一下视觉上的差异：


![](/data/attachment/album/202103/06/232436u4acy44z7cgzanbg.jpg)


### 自定义 Linux 终端


本教程利用 Pop!\_OS 上的 GNOME 终端来定制和调整终端的外观。但是，大多数建议也应该适用于其他终端。


对于大多数元素，如颜色、透明度和字体，你可以利用 GUI 来调整它，而不需要输入任何特殊的命令。


打开你的终端。在右上角寻找汉堡菜单。在这里，点击 “偏好设置”，如下图所示：


![](/data/attachment/album/202103/06/232436bhcrrlcm7rw5588l.jpg)


在这里你可以找到改变终端外观的所有设置。


#### 技巧 0：使用独立的终端配置文件进行定制


我建议你建立一个新的配置文件用于你的定制。为什么要这样做？因为这样一来，你的改变就不会影响到终端的主配置文件。假设你做了一些奇怪的改变，却想不起默认值？配置文件有助于分离你的定制。


如你所见，我有个单独的配置文件，用于截图和制作视频。


![终端配置文件](/data/attachment/album/202103/06/232437c1e7ww6f8weersv8.jpg)


你可以轻松地更改终端配置文件，并使用新的配置文件打开一个新的终端窗口。


![更改终端配置文件](/data/attachment/album/202103/06/232437pi4koeoc4ifkmo40.jpg)


这就是我想首先提出的建议。现在，让我们看看这些调整。


#### 技巧 1：使用深色/浅色终端主题


你可以改变系统主题，终端主题也会随之改变。除此之外，如果你不想改变系统主题。你也可以切换终端的深色主题或浅色主题，


一旦你进入“偏好设置”，你会注意到在“常规”选项中可以改变主题和其他设置。


![](/data/attachment/album/202103/06/232437ma3all345gm2hw3l.jpg)


#### 技巧 2：改变字体和大小


选择你要自定义的配置文件。现在你可以选择自定义文本外观、字体大小、字体样式、间距、光标形状，还可以切换终端铃声。


对于字体，你只能改成你系统上可用的字体。如果你想要不同的字体，请先在你的 Linux 系统上下载并安装字体。


还有一点! 要使用等宽字体，否则字体可能会重叠，文字可能无法清晰阅读。如果你想要一些建议，可以选择 [Share Tech Mono](https://fonts.google.com/specimen/Share+Tech+Mono)（开源）或 [Larabiefont](https://www.dafont.com/larabie-font.font)（不开源）。


在“文本”选项卡下，选择“自定义字体”，然后更改字体及其大小（如果需要）。


![](/data/attachment/album/202103/06/232438b2rbwwr60uurjrm0.jpg)


#### 技巧 3：改变调色板和透明度


除了文字和间距，你还可以进入“颜色”选项，改变终端的文字和背景的颜色。你还可以调整透明度，让它看起来更酷。


正如你所注意到的那样，你可以从一组预先配置的选项中选择调色板，也可以自己调整。


![](/data/attachment/album/202103/06/232438sojmrv00m0nra7kz.jpg)


如果你想和我一样启用透明，点击“使用透明背景”选项。


如果你想要和你的系统主题类似的颜色设置，你也可以选择使用系统主题的颜色。


![](/data/attachment/album/202103/06/232439rlz595pjxj9zdt5t.jpg)


#### 技巧 4：调整 bash 提示符变量


通常当你启动终端时，无需任何修改你就会看到你的用户名和主机名（你的发行版名称）作为 bash 提示符。


例如，在我的例子中，它会是 “ankushdas@pop-os:~$”。然而，我把 [主机名永久地改成了](https://itsfoss.com/change-hostname-ubuntu/) “itsfoss”，所以现在看起来像这样：


![](/data/attachment/album/202103/06/232439kol5c8enqe5hhwei.jpg)


要改变主机名，你可以键入：



```
hostname 定制名称

```

然而，这只适用于当前会话。因此，当你重新启动时，它将恢复到默认值。要永久地更改主机名，你需要输入：



```
sudo hostnamectl set-hostname 定制名称

```

同样，你也可以改变你的用户名，但它需要一些额外的配置，包括杀死所有与活动用户名相关联的当前进程，所以我们会跳过用它来改变终端的外观/感觉。


#### 技巧 5：不推荐：改变 bash 提示符的字体和颜色（面向高级用户）


然而，你可以使用命令调整 bash 提示符的字体和颜色。


你需要利用 `PS1` 环境变量来控制提示符的显示内容。你可以在 [手册页](https://linux.die.net/man/1/bash) 中了解更多关于它的信息。


例如，当你键入：



```
echo $PS1

```

在我这里输出：



```
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

```

我们需要关注的是该输出的第一部分：



```
\[\e]0;\u@\h: \w\a\]$

```

在这里，你需要知道以下几点：


* `\e` 是一个特殊的字符，表示一个颜色序列的开始。
* `\u` 表示用户名，后面可以跟着 `@` 符号。
* `\h` 表示系统的主机名。
* `\w` 表示基本目录。
* `\a` 表示活动目录。
* `$` 表示非 root 用户。


在你的情况下输出可能不一样，但变量是一样的，所以你需要根据你的输出来试验下面提到的命令。


在你这样做之前，请记住这些：


* 文本格式代码：`0` 代表正常文本，`1` 代表粗体，`3` 代表斜体，`4` 代表下划线文本。
* 背景色的颜色范围：`40` - `47`。
* 文本颜色的颜色范围：`30` - `37`。


你只需要键入以下内容来改变颜色和字体：



```
PS1="\e[41;3;32m[\u@\h:\w\a\$]"

```

这是输入该命令后 bash 提示符的样子：


![](/data/attachment/album/202103/06/232439sxaqkraxc4a0rr0a.jpg)


如果你注意到这个命令，就像上面提到的，`\e` 可以帮助我们分配一个颜色序列。


在上面的命令中，我先分配了一个**背景色**，然后是**文字样式**，接着是**字体颜色**，然后是 `m`。这里，`m` 表示颜色序列的结束。


所以，你要做的就是，调整这部分：



```
41;3;32

```

命令其余部分应该是不变的，你只需要分配不同的数字来改变背景色、文字样式和文字颜色。


要注意的是，这并没有特定的顺序，你可以先指定文字样式，再指定背景色，最后指定文字颜色，如 `3;41;32`，这里的命令就变成了：



```
PS1="\e[3;41;32m[\u@\h:\w\a\$]"

```

![](/data/attachment/album/202103/06/232440fogg6l34rg3grm3l.jpg)


正如你所注意到的，无论顺序如何，颜色的定制都是一样的。所以，只要记住自定义的代码，并在你确定你想把它作为一个永久的变化之前，试试它。


上面我提到的命令会临时定制当前会话的 bash 提示符。如果你关闭了会话，你将失去这个自定义设置。


所以，要想把它变成一个永久的改变，你需要把它添加到 `.bashrc` 文件中（这是一个配置文件，每次加载会话时都会加载）。


![](/data/attachment/album/202103/06/232441zb2il5j7rbxn7m7z.png)


简单键入如下命令来访问该文件：



```
nano ~/.bashrc

```

除非你明确知道你在做什么，否则不要改变任何东西。而且，为了可以恢复设置，你应该把 `PS1` 环境变量的备份（默认情况下复制粘贴其中的内容）保存到一个文本文件中。


所以，即使你需要默认的字体和颜色，你也可以再次编辑 `.bashrc` 文件并粘贴 `PS1` 环境变量。


#### 附赠技巧：根据你的墙纸改变终端的调色板


如果你想改变终端的背景和文字颜色，但又不知道该选哪种颜色，你可以使用一个基于 Python 的工具 Pywal，它可以 [根据你的壁纸](https://itsfoss.com/pywal/) 或你提供的图片自动改变终端的颜色。


![](/data/attachment/album/202103/06/232442cmm9mfoxxqf9o2c1.jpg)


如果你有兴趣使用这个工具，我之前已经详细[介绍](https://itsfoss.com/pywal/)过了。


### 总结


当然，使用 GUI 定制很容易，同时也可以更好地控制你可以改变的东西。但是，需要知道命令也是必要的，万一你开始 [使用 WSL](https://itsfoss.com/install-bash-on-windows/) 或者使用 SSH 访问远程服务器，无论如何都可以定制你的体验。


你是如何定制 Linux 终端的？在评论中与我们分享你的秘方。




---


via: <https://itsfoss.com/customize-linux-terminal/>


作者：[Ankush Das](https://itsfoss.com/author/ankush/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

The terminal emulator or simply the terminal is an integral part of any Linux distribution.

When you change the theme of your distribution, the terminal often gets a makeover automatically. But that doesn’t mean you cannot customize the terminal further.

Many It’s FOSS readers have asked us how come the terminal in our screenshots or videos look so cool, what fonts do we use, etc.

To answer this frequent question, I’ll show you some simple and some complex tweaks to change the appearance of the terminal. You can compare the visual difference in the image below:

## Customizing Linux Terminal

For most elements like color, transparency, and fonts, you can utilize the GUI to tweak it without requiring you to enter any special commands.

Open your terminal. In the top right corner, look for the hamburger menu. Here, click on “**Preferences**” as shown in the screenshot below:

![Linux Terminal Preferences](https://itsfoss.com/content/images/wordpress/2021/01/linux-terminal-preferences.jpg)

This is where you’ll find all the settings to change the appearance of the terminal.

### Tip 0: Use separate terminal profiles for your customization

I would advise you to create a new profile for your customization. Why? Because this way, your changes won’t impact the main terminal profile. Suppose you make some weird changes and cannot recall the default value. Profiles help separate the customization.

As you can see, Abhishek has separate profiles for taking screenshots and making videos.

![Terminal Profiles](https://itsfoss.com/content/images/wordpress/2021/02/terminal-profiles-800x619.jpg)

You can easily change the terminal profiles and open a new terminal window with the new profile.

![Change Terminal Profile](https://itsfoss.com/content/images/wordpress/2021/02/change-terminal-profile.jpg)

That was the suggestion I wanted to put forward. Now, let’s see those tweaks.

### Tip 1: Use a dark/light terminal theme

You may change the system theme and the terminal theme gets changed. Apart from that, you may switch between the dark or light theme, if you do not want to change the system theme.

Once you head into the preferences, you will notice the General options to change the theme and other settings.

![Terminal Theme](https://itsfoss.com/content/images/wordpress/2021/01/terminal-theme.jpg)

### Tip 2: Change the font and size

Select the profile that you want to customize. Now you’ll get the option to customize the text appearance, font size, font style, spacing, cursor shape, and toggle the terminal bell sound as well.

For [changing the terminal font](https://itsfoss.com/change-terminal-font-ubuntu/), you can only change to what’s available on your system. If you want something different, download and install the font on your Linux system first.

[Share Tech Mono](https://fonts.google.com/specimen/Share+Tech+Mono)(open source) or

[Larabiefont](https://www.dafont.com/larabie-font.font)(not open source).

Under the Text tab, select Custom font and then change the font and size (if required).

![Terminal Customization 1](https://itsfoss.com/content/images/wordpress/2021/01/terminal-customization-1.jpg)

### Tip 3: Change the color pallet and transparency

Apart from the text and spacing, you can access the “Colors” tab and [change the color of the text and background of your terminal](https://itsfoss.com/change-terminal-color-ubuntu/). You can also adjust the transparency to make it look even cooler.

As you can notice, you can change the color palette from a set of pre-configured options or tweak it yourself.

![Terminal Color Customization](https://itsfoss.com/content/images/wordpress/2021/01/terminal-color-customization.jpg)

If you want to enable transparency just like I did, you click on “**Use transparent background**” option.

You can also choose to use colors from your system theme if you want a similar color setting to your theme.

![Linux Terminal](https://itsfoss.com/content/images/wordpress/2021/01/linux-terminal.jpg)

### Tip 4: Tweaking the bash prompt variables

Usually, you will see your username and hostname (your distribution) as the bash prompt when launching the terminal without any changes.

For instance, it would be “ankushdas**@**pop-os**:~$**” in my case. However, I [permanently changed the hostname](https://itsfoss.com/change-hostname-ubuntu/) to “**itsfoss**“, so now it looks like this:

![Itsfoss Hostname](https://itsfoss.com/content/images/wordpress/2021/01/itsfoss-hostname.jpg)

To change the hostname, you can type in the following:

`hostname CUSTOM_NAME`


However, this will be applicable only to the current sessions. So, when you restart, it will revert to the default. To permanently change the hostname, you need to type in the following:

`sudo hostnamectl set-hostname CUSTOM_NAME`


Similarly, you can also change your username, but it requires some additional configuration that includes killing all the current processes associated with the active username, so we’ll avoid it to change the look/feel of the terminal.

### Tip 5: Changing the font and color of the bash prompt (for advanced users)

You can tweak the font and color of the bash prompt (**ankushdas@itsfoss:~$**) using commands.

You will need to utilize the **PS1** environment variable which controls what is being displayed as the prompt. You can learn more about it on the [man page](https://linux.die.net/man/1/bash).

For instance, when you type in:

`echo $PS1`


The output in my case is:

`\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$`


We need to focus on the first part of the output:

`\[\e]0;\u@\h: \w\a\]$`


Here, you need to know the following:

**\e**is a special character that denotes the start of a color sequence**\u**indicates the username followed by the @ symbol**\h**denotes the hostname of the system**\w**denotes the base directory**\a**indicates the active directory**$**indicates non-root user

The output in your case can be different, but the variables will be the same, so you need to play with the commands mentioned below depending on your output.

Before you do that, keep these in mind:

- Codes for text format:
**0**for normal text,**1**for bold,**3**for italic and**4**for underline text - Color range for background colors:
**40-47** - Color range for text color:
**30-37**

You just need to type in the following to change the color and font:

`PS1="\e[41;3;32m[\u@\h:\w\a\$]"`


This is how your bash prompt will look like after typing the command:

![Terminal Bash Prompt Customization](https://itsfoss.com/content/images/wordpress/2021/01/terminal-bash-prompt-customization.jpg)

If you notice the command properly, as mentioned above, \e helps us assign a color sequence.

In the command above, I’ve assigned a **background color first**, then the **text style**, and then the **font color** followed by “**m**“.

Here, “**m**” indicates the end of the color sequence.

So, all you have to do is, play around with this part:

`41;3;32`


The rest of the command should remain the same, you just need to assign different numbers to change the background color, text style, and text color.

Do note that this is in no particular order; you can assign the text style first, background color next, and the text color at the end as “**3;41;32**“, where the command becomes:

`PS1="\e[3;41;32m[\u@\h:\w\a\$]"`


![Linux Terminal Customization 1s](https://itsfoss.com/content/images/wordpress/2021/01/linux-terminal-customization-1s.jpg)

As you can notice, the color customization is the same no matter the order. So, keep the codes for customization in mind and play around with it until you’re sure you want this as a permanent change.

The above command that I mentioned temporarily customizes the bash prompt for the current session. If you close the session, you will lose the customization.

So, to make this a permanent change, you need to add it to **.bashrc** file (this is a configuration file that loads up every time you load up a session).

![Bashrch Customization Terminal](https://itsfoss.com/content/images/wordpress/2021/01/bashrch-customization-terminal-800x615.png)

You can access the file by simply typing:

`nano ~/.bashrc`


Unless you’re sure what you’re doing, do not change anything. And, just for the sake of restoring the settings back, you should keep a backup of the PS1 environment variable (copy-paste what’s in it by default) to a text file.

So, even if you need the default font and color, you can again edit the **.bashrc file** and paste the PS1 environment variable.

### Bonus Tip: Change the terminal color pallet based on your wallpaper

If you want to change the terminal's background and text color but are unsure which colors to pick, you can use a Python-based tool, Pywal. It [automatically changes the color of the terminal based on your wallpaper](https://itsfoss.com/pywal/) or the image you provide to it.

![Change Linux terminal color based on wallpaper](https://itsfoss.com/content/images/wordpress/2020/08/wallpy-2.jpg)

If you are interested in using this tool, I have written about it in detail.

## Wrapping Up

Of course, it is easy to customize using the GUI while getting better control of what you can change. But, knowing the commands is also necessary in case you start [using WSL](https://itsfoss.com/install-bash-on-windows/) or access a remote server using SSH; you can customize your experience no matter what.

If you are not much into customizing, you can try [using other Linux terminals](https://itsfoss.com/linux-terminal-emulators/) like Tilix or Terminator.

[Top 14 Terminal Emulators for Linux (With Extra Features or Amazing Looks)Want a terminal that looks cool or has extra features? Here are the best Linux terminal emulators you can get.](https://itsfoss.com/linux-terminal-emulators/)![](https://itsfoss.com/content/images/wordpress/2021/03/best-terminal-emulators.png)


![](https://itsfoss.com/content/images/wordpress/2021/03/best-terminal-emulators.png)

How do you customize the Linux terminal? Share your secret ricing recipe with us in the comments.