Skip to content

Instantly share code, notes, and snippets.

@FedericoPonzi
Created July 27, 2016 08:41
Show Gist options
  • Save FedericoPonzi/cd7195f9e4a30c23ed1f8e0a52affc54 to your computer and use it in GitHub Desktop.
Save FedericoPonzi/cd7195f9e4a30c23ed1f8e0a52affc54 to your computer and use it in GitHub Desktop.
A sample log rotate script, will keep the 5 newest files in this folder
#!/bin/bash
# 1. ls this directory
# 2. Remove from the list the 5 most recent files
# 3. Remove from the directory the remaining files.
ls | grep -v "$(ls -t | head -n 5)" | xargs -n 1 rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment