Usually when I'm searching the logs, its for something that happened recently. I end up tabbing at bash prompt to complete the names.
I finally did bash alias that uses date arithmetic to build the file name. Something like following
grep <test> `date '+localhost_access_log.%C%y-%2m-%2d.txt' -d "-3 days"` grep 400 `date '+localhost_access_log.%C%y-%2m-%2d.txt' -d "-2 days"` grep 400 `date '+localhost_access_log.%C%y-%2m-%2d.txt' -d "-1 days"` grep 400 `date '+localhost_access_log.%C%y-%2m-%2d.txt' -d "-0 days"`
Is there anyway to optimize this? Ideally I would like to create multiple aliases to grep through most recent three files like localhost_access_log.2019-06-24.txt or api-2019-06-24-1.log and don't like date command code duplication. Essentially looking for help for a bash function that will return 4 most recent file names based on the pattern I send including today's log file and can be passed to grep command