Recent Events
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:
lsto make a list of files (with paths) sorted by recencyheadto clip the top 3xargsto run those three intotailto 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 "{}"'
Comments
Sign in or become a Workroom Productions member to read and leave comments.