Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active April 22, 2024 07:57
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fernandoaleman/4dc2e514f612bc376d0f54cc3d15b608 to your computer and use it in GitHub Desktop.
Save fernandoaleman/4dc2e514f612bc376d0f54cc3d15b608 to your computer and use it in GitHub Desktop.
How to clean up Ubuntu

How To Clean Up Ubuntu

Some simple ways to free up space on Ubuntu

Remove Unnecessary Packages and Dependencies

apt-get autoremove

Clean Apt Cache

Check the amount of apt-cache on your system

du -sh /var/cache/apt

Remove all apt-cache from your system

apt-get clean

Uninstall Pakcages You Never Use

Remove specific packages

apt-get remove package-1 package-2

Remove packages and dependencies that are no longer required

apt-get autoremove

Remove Old Kernels

List your current version of linux kernel

umame -sr

Check how many linux kernels versions are installed

dpkg -l | grep linux-image | awk '{print$2}' | wc -l

Check which linux kernels versions are installed

dpkg -l | grep linux-image | awk '{print$2}'

Find the linux image number and set the LINUXIMAGE, for example linux-image-3.13.0

LINUXIMAGE=linux-image-3.13.0

Find the linux image extra number and set the LINUXIMAGEEXTRA, for example linux-image-extra-3.13.0

LINUXIMAGEEXTRA=linux-image-extra-3.13.0

Find the lowest version number and set the STARTNUM, for example 50

STARTNUM=50

Find the version number before the current version and set the ENDNUM, for example 100

ENDNUM=100

Automagically delete all the old kernel versions

for i in $(seq $STARTNUM $ENDNUM); do apt remove --purge $LINUXIMAGE-$i-generic -y; done
for i in $(seq $STARTNUM $ENDNUM); do apt remove --purge $LINUXIMAGEEXTRA-$i-generic -y; done
@emanuti
Copy link

emanuti commented Apr 8, 2024

Thanks for share! Repkace umame -sr by uname -sr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment