温馨提示×

linux nohup日志如何实时看

小樊
42
2026-10-24 02:01:35
栏目: 智能运维

在 Linux 下,用 nohup 启动程序通常会把输出重定向到日志文件(如 nohup.out 或自定义日志)。实时查看日志常用以下几种方式:


1. 使用 tail -f(最常用)

tail -f nohup.out
  • 实时显示文件新增内容
  • Ctrl + C 退出

如果日志很大,只看最后 100 行并实时:

tail -n 100 -f nohup.out

2. 使用 tail -F(更健壮)

tail -F nohup.out
  • 文件被删除或重建后仍能继续跟踪
  • 适合日志轮转(log rotate)场景

3. 使用 less +F(可搜索)

less +F nohup.out
  • 实时跟踪日志
  • 按 Ctrl + C 停止滚动,可搜索(/关键字)
  • 按 F 恢复实时跟踪

4. 使用 multitail(多日志同时看)

multitail nohup.out
  • 支持分屏、彩色、多文件

5. 使用 watch(不适合大日志,但可用)

watch -n 1 "tail -n 20 nohup.out"
  • 每 1 秒刷新一次

补充说明

nohup 启动并指定日志

nohup python app.py > app.log 2>&1 &

然后:

tail -f app.log

查看进程是否在写日志

lsof | grep app.log

✅ 推荐组合:

  • 日常查看:tail -f
  • 日志会轮转:tail -F
  • 需要搜索:less +F

如果你有具体的命令或日志文件名,我可以给你更精确的示例。

0 踩