linux shell sh 脚本开机自启动

文章目录

  • [1. 写脚本](#1. 写脚本)
  • [2. 给权限](#2. 给权限)
  • [3. 设自启](#3. 设自启)

1. 写脚本

写一个shell脚本

随便举个例子,每次开机在/home下touch个aa.txt

sh 复制代码
# 创建脚本
touch my_shell.sh

# 编写内容:
#!/bin/bash
touch /home/aa.txt

2. 给权限

给编写的脚本执行权限

sh 复制代码
sudo chmod +x  my_shell.sh

3. 设自启

sh 复制代码
# 修改/etc/rc.local文件
sudo vim /etc/rc.local

# 添加刚编写代码的路径
/ ... /my_shell.sh

# 可选项:如果没有/etc/rc.local
sudo touch /etc/rc.local
sudo chmod +x /etc/rc.local
# 接着重复上述操作
相关推荐
TG:@yunlaoda360 云老大2 小时前
华为云国际站代理商GeminiDB的企业级高可用具体是如何实现的?
服务器·网络·数据库·华为云
yBmZlQzJ3 小时前
财运到内网穿透域名解析技术机制与中立评估
运维·经验分享·docker·容器·1024程序员节
Shanxun Liao3 小时前
Cenots 7.9 配置多台 SSH 互信登陆免密码
linux·运维·ssh
j_xxx404_3 小时前
Linux:第一个程序--进度条|区分回车与换行|行缓冲区|进度条代码两个版本|代码测试与优化
linux·运维·服务器
一点晖光3 小时前
jenkins优化记录
运维·jenkins
looking_for__3 小时前
【Linux】Ext系列文件系统
linux
最贪吃的虎4 小时前
Git: rebase vs merge
java·运维·git·后端·mysql
OliverH-yishuihan4 小时前
开发linux项目-在 Windows 上 基于“适用于 Linux 的 Windows 子系统(WSL)”
linux·c++·windows
yBmZlQzJ4 小时前
内网穿透工具通过端口转发实现内外网通信
运维·经验分享·docker·容器·1024程序员节
DeepHacking4 小时前
Overleaf 本地Docker部署
运维·docker·容器