Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • This is simply amazing, any idea how can I exclude bottom -n directories where n is the no. count I want to retain. for ex: I want to keep last 7 days, so it will just remove bottom 7 and then give me the result Commented Apr 10, 2020 at 17:05
  • 2
    Use .. | tail -n7 too keep just the last 7, or .. | head -n -7 to keep all but the last 7. Commented Apr 10, 2020 at 17:08
  • That was very helpful. I am marking this as the accepted answer. just one request can you please explain your answer a little bit so that novices like us looking for the same issue can understand it more? Commented Apr 10, 2020 at 17:35
  • 1
    @PankajJha where should I start from? What is giving you trouble? The awk thing just prepends a YYYYMMDD (numeric year, month and day) to each line (which sorts the same numerically and lexicographically). Commented Apr 10, 2020 at 17:47
  • Got it now, Thanks Commented Apr 10, 2020 at 18:28