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
# 接着重复上述操作
相关推荐
不愿透露姓名的大鹏5 分钟前
Oracle归档日志爆满急救指南
linux·数据库·oracle·dba
飞Link6 分钟前
逆向兼容的桥梁:3to2 自动化降级工具实现全解析
运维·开发语言·python·自动化
W.W.H.17 分钟前
嵌入式常见的面试题1
linux·网络·经验分享·网络协议·tcp/ip
木白CPP18 分钟前
DMA-Buffer内核驱动API文档
linux
HXQ_晴天38 分钟前
Linux 系统的交互式进程监控工具htop
linux·服务器·网络
song8581 小时前
韦东山开发手册阅读笔记(五)
linux
LIZhang20161 小时前
linux写一个脚本实时保存内存占用情况
linux·运维·服务器
IDC02-阿杰1 小时前
Windows WSL2安装Ubuntu24.04全攻略
linux·windows
FS_Marking1 小时前
ZTP(零接触配置):实现自动化与高效的网络部署
运维·网络·自动化