So basically I have log files in /var/log/xxx.log. These log files are changed daily so I have to use: ls -lt /var/log/ in order to figure out the latest logs. I used:
ls -lt /var/log/ | head -2 | tail -1 | awk '{print $9}'
to extract the name, however how do I combine it with the directory path without "cd"? Like:
ls -lt /var/log/ | head -2 | tail -1 | awk '{print $9}' | tail -100 /var/log/[from pipe]
CodePudding user response:
You can simply replace awk '{print $9}' | tail -100 /var/log/[from pipe]
by tail -100 /var/log/$(awk '{print $9}')
CodePudding user response:
A better way to find the files inside your directory which have been changed or created less than one day ago is this:
find /var/log/ -type f -maxdepth 1 -mtime -1
Explanation:
-type f : only look for files
-maxdepth 1 : only look inside this directory
-mtime -1 : only look for the once, being changed at most one day ago
Good luck