free up space on ubuntu

Let us talk about scripts, HTML, Perl, PHP, apache, etc.
Post Reply
User avatar
Stevyn
SysOp
Posts:1786
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:
free up space on ubuntu

Post by Stevyn » Thu Aug 30, 2018 7:27 pm

https://www.omgubuntu.co.uk/2016/08/5-w ... -on-ubuntu



comment by gabdub •
I use this small script in all my machines. I called it "uac" = Update And Clean.
This removes old kernels but keep the last one to go back if something goes wrong with the update.

Code: Select all

#!/bin/bash
sudo apt update
sudo apt upgrade
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove
dpkg -l | grep '^rc' | awk '{print $2}' > config_list.txt
if [ -s config_list.txt ]
then
sudo xargs dpkg --purge < config_list.txt
fi
if [ -f /var/run/reboot-required ]; then
echo '**** reboot required ****'
fi
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

User avatar
Stevyn
SysOp
Posts:1786
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:

Re: free up space on ubuntu

Post by Stevyn » Thu Dec 27, 2018 3:06 pm

Code: Select all

df -h
will show you disk space used by boot partition, etc
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

User avatar
Stevyn
SysOp
Posts:1786
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:

Re: free up space on ubuntu

Post by Stevyn » Thu May 23, 2019 5:34 pm

1. Check the current kernel version

Code: Select all

$ uname -r 
It will shows the list like below:

Code: Select all

3.19.0-64-generic
2. Remove the OLD kernels
2.a. List the old kernel

Code: Select all

$ sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r`
You will get the list of images something like below:

Code: Select all

linux-image-3.19.0-25-generic
linux-image-3.19.0-56-generic
linux-image-3.19.0-58-generic
linux-image-3.19.0-59-generic
linux-image-3.19.0-61-generic
linux-image-3.19.0-65-generic
linux-image-extra-3.19.0-25-generic
linux-image-extra-3.19.0-56-generic
linux-image-extra-3.19.0-58-generic
linux-image-extra-3.19.0-59-generic
linux-image-extra-3.19.0-61-generic
2.b. Now its time to remove old kernel one by one as

Code: Select all

$ sudo apt-get purge linux-image-3.19.0-25-generic
$ sudo apt-get purge linux-image-3.19.0-56-generic
$ sudo apt-get purge linux-image-3.19.0-58-generic
$ sudo apt-get purge linux-image-3.19.0-59-generic
$ sudo apt-get purge linux-image-3.19.0-61-generic
$ sudo apt-get purge linux-image-3.19.0-65-generic
When you're done removing the older kernels, you can run this to remove ever packages you won't need anymore:

Code: Select all

$ sudo apt-get autoremove
And finally you can run this to update grub kernel list:

Code: Select all

$ sudo update-grub
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

Post Reply