Skip to content

Instantly share code, notes, and snippets.

@kshaa
Created April 20, 2019 11:13
Show Gist options
  • Save kshaa/ee2a547eca945750ba2d579b6ad255df to your computer and use it in GitHub Desktop.
Save kshaa/ee2a547eca945750ba2d579b6ad255df to your computer and use it in GitHub Desktop.
# Source - https://superuser.com/questions/268344/how-do-i-delete-all-but-10-newest-files-in-linux
# Remove all files except the newest 5
preserveCount=5
path="./rotate"
ls -1tr $path | head -n "-$preserveCount" | xargs -I {} -d '\n' rm -f $path/{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment