在 CentOS 中,nohup
命令用于在后台运行程序,即使关闭终端或断开连接,程序也会继续运行
方法一:使用分号(;)分隔命令
nohup command1 ; nohup command2 &
方法二:使用 &&
运行多个命令
nohup command1 && nohup command2 &
方法三:将所有命令写入一个 shell 脚本
run_multiple_commands.sh
的 shell 脚本文件:#!/bin/bash
command1
command2
chmod +x run_multiple_commands.sh
nohup
运行脚本:nohup ./run_multiple_commands.sh &
方法四:使用 &
将每个命令放入后台运行
command1 & nohup command2 &
注意:在使用这些方法时,请确保将 command1
和 command2
替换为您要运行的实际命令。在每个命令之后添加 &
符号可以让命令在后台运行。这样,即使您关闭终端或断开连接,这些命令也会继续运行。