Quote:
Originally Posted by l0f4r0
Maybe you could just take the "last" one (see warning below) as input with something like:
Code:
sort -rn $(ls -c localhost_access_log.*.txt | head -n 1) | head -n 5 | sed -e 's|^.*\s\(.*\)$|\1|' | less -S
EDIT: option -c with ls instead of -t. /!\ Since -c option sorts by ctime (there doesn't seem to be an easy and universal way to sort by creation time), it works as long as information about the log files are not modified otherwise your sort output could be different from what you would have expected...
|
Update:
Code:
ls -1 localhost_access_log.*.txt | sort -rt'.' -k2.1,2.4 -k2.6,2.7 -k2.9,2.10 | head -1
is even better as it takes your last log file for sure!
Explanation: as the filenames display the date, this command is sorting filenames by year, then by month and finally by day. -r option reverses the order (most recent first).