Created
January 21, 2022 13:13
-
-
Save adlerweb/fb73eae47ee8af1902ae1fe1ff89fbed to your computer and use it in GitHub Desktop.
Gentoo: Clean old kernel files located in /boot (genkernel) - Use at your own risk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import re | |
os.chdir('/boot') | |
files=(os.listdir('/boot')) | |
keep = [ | |
'kernel', | |
'kernel.old', | |
'initramfs', | |
'initramfs.old', | |
'System.map', | |
'System.map.old' | |
] | |
match = [ | |
r'^vmlinu[xz]\-', | |
r'^initramfs\-', | |
r'^System.map\-' | |
] | |
si = [ | |
'B', | |
'kB', | |
'MB', | |
'GB', | |
'TB', | |
'PB', | |
'EB' | |
] | |
for file in keep: | |
if os.path.islink(file): | |
keep.append(os.readlink(file)) | |
files = list(set(files) - set(keep)) | |
files.sort() | |
cleansize = 0 | |
for file in files: | |
delme = False | |
for m in match: | |
if re.search(m, file): | |
delme = True | |
if delme: | |
print("[!!] " + file) | |
cleansize += os.path.getsize(file) | |
os.remove(file) | |
else: | |
print("[ ] " + file) | |
csiu = "" | |
csi = cleansize | |
for siu in si: | |
if csi > 5: | |
csiu = siu | |
csi /= 1024 | |
print("Cleaned " + str(round(csi * 1024)) + csiu) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment