开机自启动
/etc/rc.d/rc.local 用于添加开机启动命令
/etc/rc.local是/etc/rc.d/rc.local的软连接
软连接相当于windows的快捷键
嵌入式Linux只有:
- 文件:
/etc/rc.local
- 目录:
/etc/rc0.d
- 目录:
/etc/rc1.d
- 目录:
/etc/rc2.d
- 目录:
/etc/rc3.d
- 目录:
/etc/rc4.d
- 目录:
/etc/rc5.d
- 目录:
/etc/rc6.d
- 目录:
/etc/rcS.d
vi /etc/rc.local
我的这个文件:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 30000 > /proc/sys/vm/min_free_kbytes
echo "0" > /sys/class/graphics/fb0/blank
source /etc/profile
/opt/qt5.5.1/apps/QDesktop/QDesktop >/dev/null 2>&1 &
exit 0
从这里可以看到:
- 第一行不知道啥意思
- 第二行也不知道啥意思
- 第三行:就执行生效一下环境配置文件/etc/profile
- 第四行:应该是加载桌面
- 第五行:退出
环境变量
在 /etc/profile
文件中设置的变量是全局变量。
.bashrc
文件(在用户的家目录下)则只对当前用户有用。~/.bashrc
、~/.bash_file
是当前用户目录下的配置信息。
修改后用 source 命令更新。
vi /etc/profile
修改完毕后,使用source
命令进行生效环境变量的配置。
source /etc/profile
重新上电后需要重新source
一下才能生效。
在/etc/profile
中有一段代码的解释:
if [ -d /etc/profile.d ]; then # 判断/etc/profile.d是不是一个目录
for i in /etc/profile.d/*.sh ; do # 若为目录,则进到该目录下,取出每个shell程序
if [ -f $i -a -r $i ]; then # 如果该shell可以执行
. $i # 就执行它
fi
done
unset i
fi
其实就是加载/etc/profile.d
中的shell脚本。
总结
- 开机自启动:
/etc/rc.local
– 包含加载source /etc/profile
- 加载
/etc/profile
– 又可以加载/etc/profile
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!