有时候,当你登录进入到Linux桌面后,可能想自动启动某个程序。这类启动程序在你登录进入到桌面后,可以进行面向整个系统的配置(比如自动代理),或者针对特定用户的桌面定制(比如Conky)。
大多数Linux桌面环境有各自的图形用户界面(GUI),让用户可以配置针对特定用户的自动启动程序或服务。
我在本教程中将介绍如何在各种Linux桌面环境下,自动启动某个程序。
GNOME桌面环境
在终端中运行这个命令,启动"Startup Applications Preferences"(启动应用程序首选项)GUI。
$gnome-session-properties

点击"Add"(添加)按钮,即可配置一个新的启动应用程序。分别往"Name"(名称)栏和"Command"(命令)栏里面键入该应用程序的名称和该应用程序的CLI命令。往"Comment"(注释)栏里面键入可选的描述。

Unity桌面环境
在Unity Dash中键入"startup"(启动)。一旦"Startup Application"(启动应用程序)图标出现,就点击该图标。

一旦"Startup Applications Preferences"(启动应用程序首选项)窗口打开,输入"Name"(名称)、"Command"(命令)和"Comment"(注释),即可配置自动启动的某个程序。

KDE桌面环境
首先,打开"System Settings"(系统设置)窗口。你会在System Administration(系统管理)下面找到"Startup and Shutdown"(启动和关闭)图标。点击该图标。

系统会要求你从一系列已知的应用程序中选择自动启动的某个应用程序。如果你的程序没有列出来,在上面空白区输入该应用程序的名称。如果该程序(比如CLI命令)将在终端中运行,就要选中"Run in terminal"(终端中运行)复选框。点击"OK"(确定)按钮。

下一步,系统要求你输入该应用程序的详细信息,包括名称、命令和描述。

之后,你会看到该程序已完成配置,可自动运行。想配置额外的启动程序/脚本,你可以点击右边侧边栏中的"Add Program"(添加程序)按钮或"Add Script"(添加脚本)按钮。

MATE桌面环境
在MATE桌面上,依次进入到"Applications"(应用程序)-> "Preferences(首选项)-> "Startup Applications"(启动应用程序)。

你会看到"Startup Applications Preferences"(启动应用程序首选项)窗口。点击"Add"(添加)按钮。

输入启动应用程序的详细信息:"Name"(名称)、"Command"(命令)和"Comment"(注释)。

Xfce桌面环境
从Xfce桌面菜单中选择"Settings Manager"(设置管理器)。在"Settings"(设置)窗口中,点击"Session and Startup"(会话和启动)图标。

在"Application Autostart"(应用程序自动启动)选项卡下,点击底部的"Add"(添加)按钮。

输入自动启动的某个程序的详细信息:"Name"(名称)、"Command"(命令)和"Description"(描述)。

LXDE桌面环境
想在LXDE桌面环境下配置启动应用程序,只需在终端中运行下面几个命令。
$mkdir-p~/.config/lxsession/Lubuntu/
$touch~/.config/lxsession/Lubuntu/autostart
$leafpadautostart
然后,把下面这一项添加到已创建的自动启动文件中:
@conky
这里,"conky"是登录后,我想自动运行的那个CLI命令的名称。
保存并关闭。