nohup 默认会把**标准输出(stdout)和标准错误(stderr)**写到当前目录(或用户主目录)下的日志文件里,具体在哪要看你当时是怎么运行的。
nohup command &
./nohup.out(当前目录)$HOME/nohup.out查看:
cat nohup.out
tail -f nohup.out
less nohup.out
如果你执行过类似:
nohup command > app.log 2>&1 &
或
nohup command > logs/app.log 2>&1 &
那日志就在你指定的文件里:
logs/app.log
查看:
tail -f logs/app.log
ps -ef | grep 命令名
ls -l /proc/进程ID/fd
1 → 标准输出2 → 标准错误| 场景 | 命令 |
|---|---|
| 实时查看 | tail -f nohup.out |
| 查看最后 100 行 | tail -n 100 nohup.out |
| 分页查看 | less nohup.out |
| 搜索关键字 | grep "ERROR" nohup.out |
正式环境 不建议用 nohup.out,而是:
nohup command > logs/app.log 2>&1 &
或使用 systemd / supervisor 管理。
如果你愿意,可以把你运行的 nohup 命令贴出来,我可以直接告诉你日志在哪。