0

I use logrotate for nginx and php logs. By default it names files like:

access.log access.log.1 access.log.2.gz ... access.log.10.gz

I want to open all of the log files in less so I can search across them all etc. The problem is the naming scheme means less doesn't open them in the correct order if I open them with:

less access.log*

How do I do this right?

logrotate config:

/var/log/nginx/*.log {
daily
rotate 14
missingok
compress
delaycompress
notifempty
sharedscripts
prerotate
    if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
        run-parts /etc/logrotate.d/httpd-prerotate; \
    fi \
endscript
postrotate
    invoke-rc.d nginx rotate >/dev/null 2>&1 || true
    passenger-config reopen-logs >/dev/null 2>&1 || true
endscript
}
  • 1
    The "problem" is that default sorting in your shell is in lexicographical order where access.log1 comes before access.log10 and both come before access.log2 and you want numerical ordering. That is not really a logrotate issue but more on how to use your shell correctly. less access.log? access.log?? might already be good enough for your purpose or consider less $(ls | sort -rV) – HBruijn Dec 12 '18 at 13:42
  • I think you're right @HBruijn that seems like a simple solution. If you'd like to add it as an answer I'll mark it accepted – Mark Robinson Dec 12 '18 at 16:12
  • Just found you don't need sort, just ls is enough: less $(ls -rv) – Mark Robinson Dec 12 '18 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.