linux常用命令收集

/ 技术收藏 / 没有评论 / 655浏览

一.设置开机自启动

1.赋予脚本可执行权限(/root/autostart.sh是你的脚本路径)

chmod +x /root/autostart.sh

2.打开/etc/rc.d/rc.local文件,在末尾增加如下内容

/root/autostart.sh

3.在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限

chmod +x /etc/rc.d/rc.local

上述方法现在已不建议使用,更推荐使用systemd的方式。

第一步,创建service文件

vi /etc/systemd/system/myautostart.service

第二步,粘贴插入以下代码

[Unit]

Description=myautostart service

After=caddy.service

[Service]

Type=forking

ExecStart=/bin/sh /root/autostart.sh

[Install]

WantedBy=multi-user.target

第三步,配置服务自启动

开机启动:systemctl enable myautostart

启动:systemctl start myautostart

关闭:systemctl stop myautostart

重启:systemctl restart myautostart

查看状态:systemctl status myautostart

修改服务配置重新生效:systemctl daemon-reload

二.清除命令记录

1.清除登陆系统成功的记录

echo > /var/log/wtmp

2.清除登陆系统失败的记录

echo > /var/log/btmp

3.清除历史执行命令

echo > ./.bash_history

三.常用命令记录

1.后台启动

nohup

2.后台启动且不输出日志

nohup xxx.sh 1>/dev/null 2>&1 &