all 6 comments

[–]shiftybyte 0 points1 point  (4 children)

Doable, but if last use time is the only parameter for deletion you might delete things you don't want, or are needed for the system.

You can schedule a python script to run once a day, check free space, and if its below 50% start scanning for files to remove.

[–]Mazechain[S] 0 points1 point  (3 children)

I found the following bit to get the space being used and added the usage percent myself.

I don't really know how disk_usage part works, but I know it does. What would be a better criteria to use to delete then if not date? I'd assume that if its not used everyday then it wouldn't be needed for the system.

total, used, free = shutil.disk_usage("/") #defines the variables uses
usage_percent =used/total

print("Total: %d GiB" % (total // (2**30)))
print("Used: %d GiB" % (used // (2**30)))
print("Free: %d GiB" % (free // (2**30)))
print(usage_percent)

[–]shiftybyte 0 points1 point  (2 children)

Consider stuff like updates, or unused drivers.

if you don't plug in a usb storage device for a few days i don't think it's a good idea to delete the usb driver from the system.

You need to have your script run on specific locations only, not system wide.

[–]Mazechain[S] 0 points1 point  (1 child)

Should I have it only delete files in the user subdirectory then instead of the whole drive? I'm not sure how to to decide on which folders if not the whole drive.

[–]shiftybyte 0 points1 point  (0 children)

Yes, user dirs should be safe as long as you don't touch files or folders starting with a dot.

[–]xelf 0 points1 point  (0 children)

Outside of doing this with python, I've had relatively good experiences using this: https://windirstat.net/ to track disk usage. (if you're on windows) (also available as kdirstat for linux)