在Debian系統中,使用nohup
命令運行的程序會將輸出重定向到一個名為nohup.out
的文件中。要搜索這個文件中的內容,你可以使用grep
命令。以下是一些示例:
grep "search_string" nohup.out
將search_string
替換為你想要搜索的字符串。
grep -E "string1|string2|string3" nohup.out
將string1
、string2
和string3
替換為你想要搜索的字符串。
grep -n "search_string" nohup.out
將search_string
替換為你想要搜索的字符串。這將在輸出中顯示包含該字符串的行及其行號。
如果你想要實時搜索nohup.out
文件中的新內容,可以使用tail
命令結合grep
:
tail -f nohup.out | grep "search_string"
將search_string
替換為你想要搜索的字符串。這將實時顯示包含該字符串的新行。
注意:如果你知道日志文件可能會變得很大,可以考慮使用grep
的--line-buffered
選項來減少緩沖延遲:
tail -f --line-buffered nohup.out | grep --line-buffered "search_string"