March 13, 2018 · One-liner Server

Remove All except three newest files one-liner

find . -type f -printf '%[email protected]\t%p\n' |
sort -t $'\t' -g | 
head -n -3 | 
cut -d $'\t' -f 2- |
xargs rm

https://stackoverflow.com/questions/26765163/delete-all-files-except-the-newest-3-in-bash-script