February 23, 2012

find files containing "a search string" + filter out last 3 records and delete the rest

grep -lr "a search string" foldername/* | xargs ls -ltrhg | sort -k 5 -r | tail -n +3 | cut -d' ' -f7 | xargs rm

No comments:

Post a Comment

How to type letters with accent

Very useful article https://www.freecodecamp.org/news/how-to-type-letters-with-accents-on-mac/