A branch office keeps a directory of rotated application logs on a Linux host, and an analyst must search the set for one regex. Which Bash approach covers those logs?
Select an answer to reveal the explanation.
Short Explanation
When the files you need are spread through a cabinet, including the zipped folders, you search the whole cabinet rather than the top sheet. You use grep on the plain rotations and zgrep on the gzip rotations so the regex covers the directory. The trap is paging through one file by hand or executing the application to reprint old lines.
Full Explanation
Rotated logs are a set of files, some still plain text and some often gzip-compressed. Search plain rotated logs with grep and gzip-compressed rotations with zgrep so the regex covers every file in the directory. grep reads the uncompressed copies, and zgrep decompresses the gzip copies before applying the same regex. Opening the newest log in a hex editor and scanning the bytes visually until the requested pattern appears ignores older rotations and is not a search of the set. Executing the application binary so it reprints older log lines from process memory onto the console runs the program for a question the files already answer, and a stopped or restarted process will not hold those old lines. Pointing strings at the directory entry and treating that output as a regex search of every rotated log file misunderstands both tools. strings is not a regex search, and a directory entry is not the contents of every log. Exam caveat: grep on a gzip file does not decompress it, so a hit inside a compressed rotation requires zgrep or an explicit decompress. Operational check: run the search and show a matching line from an older rotation, including a gzip rotation if the directory has one, not only from the live file.