在 CentOS 上让 cmatrix 开机自动启动,常见有几种方式,取决于你用的是 CentOS 6(init) 还是 CentOS 7/8(systemd),以及你是想开机进图形界面自动跑还是终端自动跑。
下面按常见场景给你说明。
如果你希望开机后 在某个 tty 上自动运行 cmatrix:
vi /etc/systemd/system/cmatrix.service
内容示例(在 tty2 上运行):
[Unit]
Description=cmatrix autostart
After=getty.target
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix
StandardInput=tty
TTYPath=/dev/tty2
Restart=always
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable cmatrix
systemctl start cmatrix
开机后按 Ctrl+Alt+F2 就能看到 cmatrix。
如果你是自己登录系统后才想看 cmatrix:
vi ~/.bash_profile
加入:
if [ "$TERM" = "linux" ]; then
cmatrix
fi
或简单点:
echo "cmatrix" >> ~/.bash_profile
⚠ 注意:这会在每次登录终端时运行,不适合 root 生产环境。
vi /etc/init.d/cmatrix
#!/bin/bash
# chkconfig: 2345 90 10
# description: cmatrix autostart
case "$1" in
start)
/usr/bin/cmatrix &
;;
*)
echo "Usage: $0 start"
exit 1
esac
chmod +x /etc/init.d/cmatrix
chkconfig cmatrix on
如果你是 桌面版 CentOS:
cmatrix或:
cp /usr/share/applications/cmatrix.desktop ~/.config/autostart/
cmatrix: command not foundyum install cmatrix -y
如果你告诉我:
我可以给你最合适的一条命令方案。