Last active
November 13, 2024 21:44
-
-
Save Iman/8c4605b2b3ce8226b08a to your computer and use it in GitHub Desktop.
Free up disk space on Ubuntu - clean log, cache, archive packages/apt archives, orphaned packages, old kernel and remove the trash
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
#!/bin/sh | |
#Check the Drive Space Used by Cached Files | |
du -sh /var/cache/apt/archives | |
#Clean all the log file | |
#for logs in `find /var/log -type f`; do > $logs; done | |
logs=`find /var/log -type f` | |
for i in $logs | |
do | |
> $i | |
done | |
#Getting rid of partial packages | |
apt-get clean && apt-get autoclean | |
apt-get remove --purge -y software-properties-common | |
#Getting rid of no longer required packages | |
apt-get autoremove -y | |
#Getting rid of orphaned packages | |
deborphan | xargs sudo apt-get -y remove --purge | |
#Free up space by clean out the cached packages | |
apt-get clean | |
# Remove the Trash | |
rm -rf /home/*/.local/share/Trash/*/** | |
rm -rf /root/.local/share/Trash/*/** | |
# Remove Man | |
rm -rf /usr/share/man/?? | |
rm -rf /usr/share/man/??_* | |
#Delete all .gz and rotated file | |
find /var/log -type f -regex ".*\.gz$" | xargs rm -Rf | |
find /var/log -type f -regex ".*\.[0-9]$" | xargs rm -Rf | |
#Cleaning the old kernels | |
dpkg-query -l|grep linux-im* | |
#dpkg-query -l |grep linux-im*|awk '{print $2}' | |
apt-get purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | head -n -1) --assume-yes | |
apt-get install linux-headers-`uname -r|cut -d'-' -f3`-`uname -r|cut -d'-' -f4` | |
#Cleaning is completed | |
echo "Cleaning is completed" |
tyeth
commented
Oct 26, 2020
via email
This script appears designed for a headless (no desktop) setup so removes
unnecessary things accordingly (like the desktop packages) . Always read
and understand scripts before you run them from the Internet.
…On Fri, 23 Oct 2020, 14:45 Iman, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
*BE CAREFUL DO NOT USE THIS SCRIPT, YOU WILL HARM YOUR SYSTEM*
The following packages will be REMOVED:
apturl* gnome-software* gnome-software-plugin-snap* nautilus-share*
software-properties-common* software-properties-gtk* ubuntu-desktop*
ubuntu-desktop-minimal*
0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
After this operation, 8.035 kB disk space will be freed.
(Reading database ... 242150 files and directories currently installed.)
Removing nautilus-share (0.7.3-2ubuntu3) ...
Removing apturl (0.5.2ubuntu19) ...
Removing gnome-software-plugin-snap (3.36.1-0ubuntu0.20.04.0) ...
*Removing gnome-software (3.36.1-0ubuntu0.20.04.0) ...*
*Removing ubuntu-desktop (1.450.1) ...*
*Removing ubuntu-desktop-minimal (1.450.1) ...*
Removing software-properties-gtk (0.98.9.1) ...
Removing software-properties-common (0.98.9.1) ...
Perhaps those packages are outdated and there's no need to maintain them
on your machine, hence you've been prompted to allow deletion and make more
space.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/8c4605b2b3ce8226b08a#gistcomment-3501199>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTBZ42H75PKSUDBVZB42ELSMGCGZANCNFSM4MXFY5TQ>
.
Excelente! TKS
thanks :)
Nice work
It worked on Ubuntu 18.04 on DigitalOcean, ty.
nice!
Ubuntu 18.04.4 works fine
Brilliant!!
Running with 18.04 LTS. I have apps like KiCAD and PyCharm on a 34GB root file-system. Down to 6GB left clean.sh found another 5GB to clean out to give me 11GB space left.
Thanks Iman!
It worked on Ubuntu 20.04. Nearly 20GB cleaned.
thumbs up
Great work @Iman!
Never thought the cleanup is super easy with this script.
All happened in a jiffy!
Skip the step
apt-get remove --purge -y software-properties-common
Otherwise some handy steps and commands for tidying out excessive logs thanks !
Cool! Thx!
Thanks a lot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment