Ubuntu 18.04没有rc.local

rc.local用于预设一些脚本,在系统启动时候调用。而在18.04中默认没有这个文件了。解决办法很简单,先自己新建一个文件:

vim /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.

exit 0

 

然后加上可执行权限:

chmod +x /etc/rc.local

 

还想Ubuntu 16.04一样,在exit 0前加入需要执行的代码即可。

搞定!

 

Reference:

https://vpsfix.com/community/server-administration/no-etc-rc-local-file-on-ubuntu-18-04-heres-what-to-do/

https://askubuntu.com/questions/886620/how-can-i-execute-command-on-startup-rc-local-alternative-on-ubuntu-16-10/919598#919598

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.