Skip to content

Instantly share code, notes, and snippets.

@icasimpan
Created June 29, 2018 18:16
Show Gist options
  • Save icasimpan/ea1d8a4bcab042d0326ac72bbbd0bf60 to your computer and use it in GitHub Desktop.
Save icasimpan/ea1d8a4bcab042d0326ac72bbbd0bf60 to your computer and use it in GitHub Desktop.
POC shell script for keeping only the last 30 files. Useful for archives.
#!/bin/bash
cd /var/backup/files
let count=1
for each_file in $(ls -1t); do
if [ $count -le 30 ]; then
echo "[$each_file] - good"
let count=$count+1
else
echo "[$each_file] - EXPIRED!"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment