按时间查 nohup 日志,本质上就是查 nohup 输出的日志文件内容,常用方法如下:
一般两种情况:
nohup python app.py > nohup.out 2>&1 &
日志在:nohup.out
或自定义文件:
nohup python app.py > run.log 2>&1 &
日志在:run.log
查看方式:
ls -lh nohup.out
ls -lh nohup.out
find . -name "nohup.out" -mmin -30
(30分钟内修改过)
如果日志本身带时间,例如:
2026-01-21 10:23:45 INFO ...
awk '$0 >= "2026-01-21 10:00:00" && $0 <= "2026-01-21 11:00:00"' nohup.out
grep "2026-01-21 10:" nohup.out
start=$(date -d '1 hour ago' '+%Y-%m-%d %H:%M:%S')
awk -v s="$start" '$0 >= s' nohup.out
tail -f nohup.out
或只看最新 100 行:
tail -n 100 nohup.out
建议在启动程序时加时间:
Python 示例:
nohup python -u app.py >> run.log 2>&1 &
并在代码里用 logging 打时间。
✅ 查今天 10 点后的日志:
awk '$0 >= "2026-01-21 10:00:00"' nohup.out
✅ 查报错 + 时间:
grep -E "ERROR|Traceback" nohup.out | tail -n 50
如果你愿意,可以把一行日志样例或启动命令发我,我可以直接帮你写精确命令。