How Do I Grep the Latest File in Unix?
Contents How Do I Grep the Latest File? How It Works: Find /Var/Log/Folder -Type F -Printf ‘%[Email Protected] %P ’ This Looks for Files and Prints Their...
Contents
How do I grep the latest file?
How it works:
- find /var/log/folder -type f -printf ‘%[email protected] %p ’ This looks for files and prints their modification time (seconds) followed by a space and their name followed by a nul character.
- sort -rz. This sorts the null-separated data.
- sed -Ezn ‘1s/[^ ]* //p’ …
- xargs –null grep string.
Must Read
How do I find the latest file in Unix?
Get most recent file in a directory on Linux
- watch -n1 ‘ls -Art | tail -n 1’ – shows the very last files – user285594 Jul 5 ’12 at 19:52.
- Most answers here parse the output of ls or use find without -print0 which is problematic for handling annoying file-names.