学堂 学堂 学堂公众号手机端

在Ubuntu中,rc.local文件默认是不启用的,如果需要启用并使用rc.local文件,可以按照以下步骤操作: 打开终端,输入以下命令打开rc.local文件进行编辑: sudonano/etc/rc.local 在rc.local文件中添加您需要在系统启动时自动运行的命令或脚本

lewis 2年前 (2024-01-22) 阅读数 6 #技术

在Ubuntu中,rc.local文件默认是不启用的,如果需要启用并使用rc.local文件,可以按照以下步骤操作:

  1. 打开终端,输入以下命令打开rc.local文件进行编辑:
sudonano/etc/rc.local
  • 在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文件中添加的命令或脚本将会自动执行。

    版权声明

    本文仅代表作者观点,不代表博信信息网立场。

    热门