2025-06-17

紀錄:常用指令:查找大量有指定內容的檔案

Bash script

例如我現在要查 tomcat 的 log,查找說在 2020-01-10 ~ 2020-01-25 之間,連線 /api/foo/bar 這條 request 的資訊。

就能以以下指令來處理

$ cd {log 資料夾}
$ for i in {10..25} ; do sudo cat "localhost_access_log.2020-01-$i.txt" | grep "/api/foo/bar" ; done
$ cd {log 資料夾}
for /L %%i in (10, 1, 25) do (
	type "localhost_access_log.2020-01-%%i.txt" | findstr "/api/foo/bar"
)

沒有留言:

張貼留言