ubuntu自定义菜单_如何自定义Ubuntu的每日消息

本文介绍了如何自定义Ubuntu的每日消息(MOTD),包括删除默认信息、添加静态和动态消息。通过修改脚本或创建新脚本,用户可以在登录时展示个性化的系统通知,如天气信息等。
摘要由CSDN通过智能技术生成
ubuntu自定义菜单

ubuntu自定义菜单

Ubuntu displays an informative message, known as the message of the day, when a user logs in at the terminal. The MOTD is fully customizable — you can add your own text and other dynamic data.

当用户在终端上登录时,Ubuntu将显示信息性消息,即当日消息。 MOTD是完全可定制的-您可以添加自己的文本和其他动态数据。

When a user logs in, the pam_motd process executes the scripts in the /etc/update-motd.d directory and dynamically creates the message of the day. You can customize the MOTD by modifying the scripts, removing them or writing your own scripts.

当用户登录时,pam_motd进程将执行/etc/update-motd.d目录中的脚本并动态创建当天的消息。 您可以通过修改脚本,删除脚本或编写自己的脚本来自定义MOTD。

每日默认消息 (The Default Message of the Day)

The message of the day is only shown when you log into Ubuntu in text mode, not graphical mode. You can access a virtual terminal with the Ctrl-Alt-F1 shortcut if you’re using a graphical desktop — use the Ctrl-Alt-F7 shortcut to get back to your graphical desktop, also known as your X server. Ctrl-Alt-F2 through Ctrl-Alt-F6 will take you to other virtual terminals.

仅当您以文本模式而非图形模式登录Ubuntu时,才会显示当天的消息。 如果您使用的是图形桌面,则可以使用Ctrl-Alt-F1快捷方式访问虚拟终端-使用Ctrl-Alt-F7快捷方式返回图形桌面(也称为X服务器)。 Ctrl-Alt-F2到Ctrl-Alt-F6会将您带到其他虚拟终端。

Here’s Ubuntu’s standard MOTD. It shows the typical system version numbers you’ll be familiar with if you’re a long-time Linux user. It also shows dynamically generated information about available updates and static messages about Ubuntu’s license.

这是Ubuntu的标准MOTD。 如果您是长期使用Linux的用户,它将显示您会熟悉的典型系统版本号。 它还显示有关可用更新的动态生成信息以及有关Ubuntu许可证的静态消息。

添加自定义消息 (Adding a Custom Message)

Let’s say you want to add a custom message users will see when they log into your Ubuntu system. Ubuntu’s MOTD is generated by scripts when you log in, so you can’t just add it to the /etc/motd file. The place to put your own static messages is /etc/motd.tail — the contents of this file are added to the end of the MOTD when it’s generated.

假设您要添加一个自定义消息,用户登录到Ubuntu系统时将看到这些消息。 登录时,Ubuntu的MOTD是由脚本生成的,因此不能仅将其添加到/ etc / motd文件中。 放置自己的静态消息的位置是/etc/motd.tail-该文件的内容在生成时会添加到MOTD的末尾。

Let’s use the Nano text editor to open the /etc/motd.tail file with the following command: (Linux terminal wizards can use Vi or Emacs, but Nano is easier for newbies)

让我们使用Nano文本编辑器通过以下命令打开/etc/motd.tail文件:(Linux终端向导可以使用Vi或Emacs,但是Nano对于新手来说更容易)

sudo nano /etc/motd.tail

须藤nano /etc/motd.tail

This file is completely empty by default. Just enter any message you like — feel free to go crazy with black-and-white ASCII art here. Once you’re done, save the file with Ctrl+O and Enter, then exit Nano with Ctrl+X.

默认情况下,此文件完全为空。 只要输入您喜欢的任何消息,即可在这里随意使用黑白ASCII艺术。 完成后,使用Ctrl + O保存文件并按Enter,然后使用Ctrl + X退出Nano。

The next time any user logs in, they’ll see your custom message. If you want to check it out immediately, log out of the terminal with the exit command and log back in.

下次任何用户登录时,他们都会看到您的自定义消息。 如果要立即检出,请使用exit命令注销终端并重新登录。

删除信息 (Removing Information)

Now let’s say we want to remove some of the default information. It’s not just a matter of editting a single file — each section is automatically generated from a script located in the /etc/update-motd.d directory.

现在,我们要删除一些默认信息。 这不仅仅是编辑单个文件的问题-每个部分都是从/etc/update-motd.d目录中的脚本自动生成的。

You can get a full list of the files in this directory by typing /etc/update-motd.d at the terminal and pressing Tab.

通过在终端上键入/etc/update-motd.d并按Tab,可以获取此目录中文件的完整列表。

The scripts are run in numerical order, which is why they’re prefixed with numbers. You could rename the script files and change the numbers to rearrange the order of the different sections in the MOTD, if you liked.

脚本按数字顺序运行,这就是为什么要给它们加上数字前缀的原因。 如果愿意,可以重命名脚本文件并更改编号以重新排列MOTD中不同部分的顺序。

To remove a script’s information from the MOTD, we just have to prevent it from running. We can do this by removing its execute permissions with the chmod -x command.

要从MOTD中删除脚本的信息,我们只需要阻止其运行即可。 我们可以通过使用chmod -x命令删除其执行权限来实现。

If we wanted to remove the documentation text in the MOTD, we’d run the following command:

如果要删除MOTD中的文档文本,请运行以下命令:

sudo chmod -x /etc/update-motd.d/10-help-text

须藤chmod -x /etc/update-motd.d/10-help-text

The next time a user logs in, they won’t see the documentation line.

用户下次登录时,将不会看到文档行。

添加动态信息 (Adding Dynamic Information)

We can write our own scripts to add any dynamic information we like to the MOTD. As an example, let’s try using the weather-util package to create a script that adds the current local weather to the MOTD.

我们可以编写自己的脚本,将我们喜欢的任何动态信息添加到MOTD。 例如,让我们尝试使用weather-util包创建一个脚本,该脚本将当前的本地天气添加到MOTD。

It’s not installed by default, so let’s install it with the following command:

默认情况下未安装它,因此让我们使用以下命令进行安装:

sudo apt-get install weather-util

sudo apt安装weather-util

You’ll need your local International Civil Aviation Organization code, which you can get from this website. Here’s how to use weather-util with your code:

您需要本地国际民航组织的代码,可以从该网站获得。 这是在您的代码中使用weather-util的方法:

weather -i CODE

天气-i代码

Now let’s use the following command to create a script in the appropriate location and open it with Nano:

现在,让我们使用以下命令在适当的位置创建脚本并使用Nano打开它:

sudo nano /etc/update-motd.d/98-weather

须藤纳米/etc/update-motd.d/98-weather

After Nano opens, enter the following code, replacing CODE with your local weather code:

Nano打开后,输入以下代码,将CODE替换为您当地的天气代码:

#!/bin/sh

#!/ bin / sh

echo weather -i CODE echo

回声天气-i CODE回声

Press Ctrl-O and Enter to save, then press Ctrl-X to quit.

按Ctrl-O和Enter键保存,然后按Ctrl-X退出。

Make the script executable with chmod +x or it won’t run:

使用chmod + x使脚本可执行,否则它将无法运行:

sudo chmod +x /etc/update-motd.d/98-weather

须藤chmod + x /etc/update-motd.d/98-weather

Now users will see a local weather forecast when they log in. There’s nothing special about weather-util — you can use any command that prints text to the terminal.

现在,用户登录时将看到本地天气预报。weather-util没什么特别的-您可以使用任何将文本打印到终端的命令。



The MOTD isn’t only displayed when users log in locally. Any users that log in remotely with SSH or Telnet will also see your customized MOTD.

仅当用户本地登录时才显示MOTD。 使用SSH或Telnet远程登录的所有用户还将看到您自定义的MOTD。

翻译自: https://www.howtogeek.com/104708/how-to-customize-ubuntus-message-of-the-day/

ubuntu自定义菜单

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值