0

My goal is to display a list of log names, from the start time column, grepping for 20161221. I use this command:

$ ls -m1 /var/log/audit.raw.* | grep 20161221
/var/log/audit.raw.20161220173001EST.20161221000004EST.gz
/var/log/audit.raw.20161221000004EST.20161221083001EST.gz
/var/log/audit.raw.20161221083001EST.20161221163000EST.gz
/var/log/audit.raw.20161221163000EST.20161222000004EST.gz

But the first entry is from 20161220. I know I can trim it successfully with this command instead:

$ ls -m1 /var/log/audit.raw.* | grep 20161221 | tail -n +2 
/var/log/audit.raw.20161221000004EST.20161221083001EST.gz
/var/log/audit.raw.20161221083001EST.20161221163000EST.gz
/var/log/audit.raw.20161221163000EST.20161222000004EST.gz

I wanted to see if there is a more intelligent use of grep to avoid trimming the output with tail -n +2

1 Answer 1

2

What you want to do may be done using just ls:

$ ls /var/log/audit.raw.20161221*
3
  • ok I didnt even think of that and it is exactly what I needed.
    – Steve
    Feb 6, 2017 at 21:14
  • 2
    That was embarrassing :)
    – Steve
    Feb 6, 2017 at 21:15
  • @Steve Sometimes, the simplest thing is obscured by too much thinking :-) If this solves your issue, please consider accepting the answer.
    – Kusalananda
    Feb 6, 2017 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .