Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Clean out old apple updates (older than 24 hours) because softwareupdate often refuses to install them
Removes cached apple updates that are older than 24 hours
import datetime
import os
import shutil
import sys
def main():
Main event
update_dir = '/Library/Updates'
# If the directory isn't there, might as well exit
if not os.path.exists(update_dir):
now =
day_ago = now - datetime.timedelta(hours=24)
# Get all directories in /L/Updates
for item in os.listdir(update_dir):
if item == 'PreflightContainers':
if os.path.isdir(os.path.join(update_dir, item)):
modification_time = datetime.datetime.fromtimestamp(
os.stat(os.path.join(update_dir, item)).st_mtime)
if modification_time < day_ago:
# This is ick, but we would rather eat the error than
# halt the Munki run
shutil.rmtree(os.path.join(update_dir, item))
except Exception:
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment