nohup 命令通常会把输出重定向到 nohup.out 或你指定的日志文件,例如:
nohup python app.py > app.log 2>&1 &
要“过滤日志行”,常见场景和做法如下:
grep 过滤关键字tail -f app.log | grep "ERROR"
只看包含 ERROR 的行。
tail -f app.log | grep -v "DEBUG"
不显示 DEBUG 日志。
tail -f app.log | grep -E "ERROR|WARN"
tail -f app.log | grep -i "error"
grep "ERROR" app.log
grep -n "ERROR" app.log
grep -c "ERROR" app.log
grep "2026-01-21 10:" app.log
nohup python app.py 2>&1 | grep "ERROR" > error.log &
⚠️ 缺点:
tee 同时保存和过滤nohup python app.py 2>&1 | tee app.log | grep "ERROR"
如 Python 的 logging:
logging.basicConfig(level=logging.INFO)
tail -f nohup.out | grep ERROR
tail -f nohup.out | grep -v "heartbeat"
tail -f nohup.out | grep --color=auto ERROR
如果你能说明:
我可以给你更精确的命令。