Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
for dir in $(find /export/secondary2/snapshots -wholename '/export/secondary2/snapshots/*/*' -type d); do { files=$(ls "${dir}" | wc -l); if [[ "${files}" -gt 2 ]]; then echo $dir; ls -tl "${dir}"; for file in $(ls -t "${dir}" | tail --lines +3); do { read -p "Remove ${file}?" -n 1 -r; if [[ "${REPLY}" =~ ^[Yy]$ ]]; then echo " ... removing ${dir}/${file}"; rm "${dir}/${file}"; else echo " ... skipping ${dir}/${file}"; fi; } done; fi; } done
for dir in $(find /export/secondary2/snapshots -wholename '/export/secondary2/snapshots/*/*' -type d -mtime +21); do { if [[ "$(ls ${dir} | wc -l)" -lt 1 ]]; then continue; fi; ls -tl "${dir}"; read -p "Remove ${dir}?" -n 1 -r; if [[ "${REPLY}" =~ ^[Yy]$ ]]; then echo " ... removing ${dir}"; rm -rf "${dir}"; else echo " ... skipping ${dir}"; fi; } done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment