在Ubuntu中,rc.local文件默认是不启用的,如果需要启用并使用rc.local文件,可以按照以下步骤操作: 打开终端,输入以下命令打开rc.local文件进行编辑: sudonano/etc/rc.local 在rc.local文件中添加您需要在系统启动时自动运行的命令或脚本
在Ubuntu中,rc.local文件默认是不启用的,如果需要启用并使用rc.local文件,可以按照以下步骤操作:
- 打开终端,输入以下命令打开rc.local文件进行编辑:
sudonano/etc/rc.local
#!/bin/sh-e
#
#rc.local
#
#Thisscriptisexecutedattheendofeachmultiuserrunlevel.
#Makesurethatthescriptwill"exit0"onsuccessoranyother
#valueonerror.
#
#Inordertoenableordisablethisscriptjustchangetheexecution
#bits.
#
#Bydefaultthisscriptdoesnothing.
#PrinttheIPaddress
_IP=$(hostname-I)||true
if["$_IP"];then
printf"MyIPaddressis%s\n""$_IP"
fi
exit0
保存并退出rc.local文件。在nano编辑器中,按下Ctrl+X,然后按Y确认保存,最后按Enter键确认文件名。
授予rc.local文件执行权限,输入以下命令:
sudochmod+x/etc/rc.local
sudoreboot
之后,系统启动时,rc.local文件中添加的命令或脚本将会自动执行。
版权声明
本文仅代表作者观点,不代表博信信息网立场。