在 Linux 下,用 grep 查看 nohup 日志(通常是 nohup.out 或你指定的日志文件)是非常常见的操作。下面按常见场景给你说明。
grep "关键字" nohup.out
例如:
grep "ERROR" nohup.out
tail -f nohup.out | grep "关键字"
示例:
tail -f nohup.out | grep "Exception"
适合看程序运行中不断产生的日志
grep -i "error" nohup.out
grep -n "error" nohup.out
grep -A 10 "Exception" nohup.out
-A 10:显示匹配行后 10 行-B 10:前 10 行-C 10:前后各 10 行grep -E "ERROR|WARN|Exception" nohup.out
grep "ERROR" nohup.out | grep "timeout"
ps -ef | grep your_program
nohup java -jar app.jar > app.log 2>&1 &
查看:
grep "ERROR" app.log
tail -n 1000 nohup.out | grep "ERROR"
grep -c "ERROR" nohup.out
tail -f nohup.out | grep -i -C 5 "exception"
grep -E "ERROR|WARN" nohup.out | tail -n 50
如果你愿意,可以告诉我:
nohup.out 还是自定义)我可以帮你写一条最合适的命令。