总是忘记ubuntu如何添加开机启动命令,在这里记录一下备忘。
第一,可视化方法:
1、终端输入: gnome-session-properties
2、弹出窗口

3、点击右侧添加

4、输入全路径的脚本命令即可。
第二种,Systemd方法:
1.新建需要启动的服务文件, 移动到systemd文件夹下:
touch fn.service
mv ./fn.service /etc/systemd/system && cd /etc/systemd/system
nano fn.service
2.编辑fn.service的文本内容, 使用nano
[Unit]
After=network.target # tell systemd when script should run
[Service]
ExecStart=/usr/local/limit-battery.sh
[Install]
WantedBy=default.target
3.载入service unit, 激活fn.service
touch fn.sh # new file name fn.sh, you want to start it on booting.
mv fn.sh /usr/local
chmod 744 /usr/local/fn.sh # 744 means current_user:7(rwx) + current_group:4® + other:4®
systemctl daemon-reload # reload systemd configuration, scan unit change
systemctl enable fn.service
systemctl start fn.service # pay attention, generally, sudo is neccssary.
本文介绍了两种在Ubuntu系统中添加开机启动命令的方法:一是通过gnome-session-properties的可视化方式,二是使用Systemd服务配置。详细步骤包括创建服务文件、编辑内容、载入服务并启用。此教程为日后快速设置开机启动脚本提供了便利。
7391

被折叠的 条评论
为什么被折叠?



