nohup(no hang-up)命令用于在后台运行程序,即使关闭终端或断开连接,程序也会继续运行
使用grep命令筛选关键字:
nohup command > output.log 2>&1 &
grep -i "keyword" output.log
这里,command是你要运行的程序,output.log是日志文件名,keyword是你想要提取的关键信息。grep -i表示忽略大小写。
使用awk或sed命令提取关键信息:
nohup command > output.log 2>&1 &
awk '/keyword/ {print}' output.log
或者
nohup command > output.log 2>&1 &
sed -n '/keyword/p' output.log
这里,awk和sed命令用于提取包含关键字的行。
使用tail命令实时查看日志:
nohup command > output.log 2>&1 &
tail -f output.log | grep --line-buffered "keyword"
这里,tail -f命令用于实时查看日志文件的最后几行,grep --line-buffered表示实时输出包含关键字的行。
请注意,这些命令示例仅适用于Unix/Linux系统。在其他操作系统上,可能需要使用不同的命令和方法。