該賞金過期2天。此問題的答案有資格獲得 50聲望賞金。 Jakub Znamená?ek希望引起更多關注這個問題:
我提供 50 分,如果有人會告訴我如何使用 less 一次搜索多個檔案(我知道如何打開多個檔案,但我只能搜索一個)
嗨,我想知道是否有可能使用 less 一次搜索多個檔案。我遇到了問題,我應該通過多個日志(instance1.log、instance2.log、instance3.log ...)并搜索一些測驗。現在我可以在較少使用的情況下打開多個檔案,less instance?.log但我需要手動搜索檔案并單獨搜索每個檔案,但我想一次搜索所有檔案。有這樣的選擇嗎?
uj5u.com熱心網友回復:
這是一個離題的問題,但您可以使用grep. 看看這個答案
uj5u.com熱心網友回復:
我不確定這是否是你想要的,但你可以做到
cat instance?.log | less
然后搜索結果。
或者使用 grep,因為它基本上是為此用例制作的工具:
grep -E 'search term' instance?.log
uj5u.com熱心網友回復:
從命令less下的手冊頁/pattern:
Certain characters are special if entered at the beginning of
the pattern; they modify the type of search rather than become
part of the pattern:
...
^E or *
Search multiple files. That is, if the search reaches
the END of the current file without finding a match, the
search continues in the next file in the command line
list.
因此,例如,使用 less 打開多個檔案:
less file1 file2
然后鍵入/^E或/*后跟您的搜索模式。用于n通過模式匹配向前導航和通過模式匹配shift n向后導航(跨越多個檔案)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/406098.html
標籤:
