在 Debian 上,如果你用 nohup 启动了一个程序,比如:
nohup python app.py > app.log 2>&1 &
那么日志一般写在 app.log 里。要看实时日志,常用下面几种方式:
tail -f实时查看日志文件新增内容:
tail -f app.log
退出:Ctrl + C
如果日志很大,避免刷屏:
tail -n 100 -f app.log
只看最后 100 行并实时刷新。
同时看多个日志:
tail -f app.log error.log
如果日志本身没时间:
tail -f app.log | while read line; do echo "$(date '+%F %T') $line"; done
less(可滚动)适合大日志:
less +F app.log
F:实时跟踪Ctrl + C:停止跟踪F 再按一次:继续跟踪nohup 默认会写到:
nohup.out
查看:
tail -f nohup.out
ps aux | grep app.py
或
jobs
如果你愿意,可以告诉我:
我可以给你更合适的命令。