nohup
(no hang-up)命令允许你在Linux系统中在后台运行程序,即使关闭终端或断开SSH连接,程序也会继续运行
打开终端。
使用SSH连接到远程服务器。例如:
ssh username@remote_host
将username
替换为你的用户名,将remote_host
替换为远程服务器的IP地址或主机名。
nohup
命令启动程序。基本语法如下:nohup command-to-run &
将command-to-run
替换为你要运行的命令。例如,如果你想在后台运行一个名为my_script.sh
的脚本,可以使用以下命令:
nohup ./my_script.sh &
nohup
命令会将程序的输出重定向到一个名为nohup.out
的文件中。你可以使用以下命令查看输出:cat nohup.out
nohup
命令结合split
命令。例如,以下命令将输出文件限制为10MB:nohup command-to-run | split -b 10M - nohup.out.part.
nohup command-to-run > log_file.out 2>&1 &
将log_file.out
替换为你希望使用的日志文件名。
nohup.out
文件以获取程序的输出和状态信息。请注意,nohup
命令并不能保证程序在所有情况下都能在后台稳定运行。对于需要更高可靠性的场景,可以考虑使用screen
或tmux
等终端复用器。