Photo by Paolo Chiabrando / Unsplash

Recent Events

tiny tool Oct 21, 2025

I wanted to see the most-recent entries of the most-recent logs.

ls -1td /var/log/*.log | head -3 | xargs -I {} sh -c 'tail -10 "{}"'

This uses:

  • ls to make a list of files (with paths) sorted by recency
  • head to clip the top 3
  • xargs to run those three into tail to pick up the bottom 10 lines.

Wrinkle 1 – listing with the paths means xargs doesn't need to be passes the path of the files.

Wrinkle 2 – {} is something uncommon to use as a pattern – no more. But it's a common pair to use, when finding things to sub for in commandline things. Presumably no use in javascript code...

This alternative separates the logs – easier to use.

ls -1td /var/log/*.log | head -3 | xargs -I {} sh -c 'echo "=== {} ==="; tail -10 "{}"'

Tags

James Lyndsay

Getting better at software testing. Singing in Bulgarian. Staying in. Going out. Listening. Talking. Writing. Making.