
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自定義菜單