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系统。在其他操作系统上,可能需要使用不同的命令和方法。