My Ubuntu cloud server has left only 900MB of disk space.
I'll just empty the directory /tmp and wondering if there is any other location to clean up.
To delete downloaded packages (.deb) already installed (and no longer needed)
sudo apt-get clean
To remove all stored archives in your cache for packages that can not be downloaded anymore (thus packages that are no longer in the repository or that have a newer version in the repository).
sudo apt-get autoclean
To remove unnecessary packages (After uninstalling an app there could be packages you don't need anymore)
sudo apt-get autoremove
To delete old kernel versions
sudo apt-get remove --purge linux-image-X.X.XX-XX-generic
If you don't know which kernel version to remove
dpkg --get-selections | grep linux-image
Source: Limpiando Ubuntu: comandos y programas (actualización) (google translated)
clean
freed up quite a bit of space. Immediately after, I ran autoclean
and my free space went down by 45MB. Running clean
again released this extra space.
Commented
Mar 11, 2013 at 0:59
dpkg --get-selections | grep linux-image
which caused me a boot error - the ubuntu disappeared from grub boot menu - this answer fixed the problem - try not remove the latest image
sudo apt-get clean
It will -simply- remove the packages all the local copy of the packages that you may have downloaded when doing an installation +upgrade. This will almost empty the /var/cache/apt/archives directory. ... So the next time you run sudo apt-get update
it will re-download everything (already there). Just a heads-up!..:)
Commented
May 18, 2017 at 21:43
dpkg --get-selections | grep linux-image
Show top 10 biggest subdirs in the current dir.
du -sk * | sort -nr | head -10
you can create this as an alias in your say: ~/.bashrc and use it
alias ducks='du -cks * | sort -rn | head'
Use File Usage Analyzer (AKA baobab; GNOME based), Filelight or kDirStat (KDE based), to see where the disk space is going visually (ncdu
uses a TUI).
Check if you have old kernels for deletion
ls -lh /boot
Cleaning packages
sudo apt autoremove
sudo apt autoclean
see list of all installed packages, sorted by size. If you see something big and don't use it - uninstall it
dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr | less
Clean unused language files with translations (there are tons of them)
sudo apt install localepurge
Check content of /var/tmp/
du -sh /var/tmp/
Check also
man deborphan
Search for big files:
find / -type f -size +1024k
or
find / -size +50000 -exec ls -lahg {} \;
Big installed packages (part of the package: debian-goodies)
dpigs
On systemd: Remove the oldest archived journal files until the disk space they use falls below the specified size
sudo journalctl --vacuum-size 10M
ncdu
, which provides a fast way to see what directories are using your disk space
Warning: journal has been rotated since unit was started, output may be incomplete.
message , how could I fix it?
ncdu / -x
is a good use in WSL (to avoid scanning outside disks)
Commented
Jan 1, 2022 at 17:12
sudo apt-get autoremove
That can clean out a lot of guff (old kernels, etc) that have been replaced. You can do a similar thing in Synaptic (load it up and select the status button and then the Auto-removeable option).
aptitude
instead of apt-get
, it can clean up as you go but it's quite common for older installations to collect a raft of installed kernels as security updates come out.
dpkg --get-selections | grep linux-image
).
I just freed up almost 2 gigs by removing old kernels and header files:
use
uname -r
to check your current version, then
dpkg -l linux-image-* linux-headers-*
to see all the old kernels and header files, then
sudo apt-get remove linux-image-<XYZ> linux-headers-<XYZ>
the apt-get remove
command supports wildcards, so you can do apt-get remove linux-image 3.0.* linux-headers-3.0.*
for example, to get rid of many at once.
Make sure you don't kill remove current kernel of course! And maybe keep one or two old version, just in case... but not 10 or 20!
Do not forget to Empty Trash.
Or from command line:
rm -r ~/.local/share/Trash/info/ && rm -r ~/.local/share/Trash/files/
Or just trash-empty
using trash-cli package.
rm.sh: ~/.local/share/Trash/info/: No such file or directory
can I directly do command rm -rf ~/.local/share/Trash/*
?
shell-safe-rm
(github.com/kaelzhang/shell-safe-rm)
Some packages can be quite large. A convenient way of finding these is to use dpigs
. It's not installed by default but can be found in debian-goodies
(GitHub project)
sudo apt-get install debian-goodies
Then:
$ dpigs
419576 texlive-latex-extra-doc
204112 nvidia-319
175463 google-chrome-stable
141058 linux-image-extra-3.11.0-15-generic
113173 libreoffice-core
104822 valgrind
102322 qt4-doc
93337 blender
91105 texlive-pstricks-doc
90517 libboost1.53-dev
There are a few options:
-n, --lines=N
Display the N largest packages on the system (default 10).
-s, --status=status-file
Use status-file instead of the default dpkg status file.
-S, --source
Display the largest source packages of binary packages installed
on the system.
-H, --human-readable
Display package sizes in human-readable format (like ls -lh or du -h)
-h, --help
Display this message.
Attention: If you've just upgraded the kernel, reboot before deleting the older versions!
Remember to check which kernel you are using type:
uname -r
Then as root:
sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
read that thread to be safe not to remove needed kernels with this command!
If you run into problems, use this script instead: https://askubuntu.com/a/1409370/34298
Check for large numbers of log files too:
sudo du -h /var/log
Or as rubo77 points out in commends, you could use the NCurses disk usage tool:
sudo ncdu /var/log
logrotate
for how to purge older logs; though under systemd logs are handled by journald and so you'll need to look at the journald conf files.
/var/log/mongodb
had 5 GB . Would it be fine to delete all logs?
I really recommend you the program BleachBit, which cleans everything on Ubuntu. Install it using the following command:
sudo apt install bleachbit
which cleans everything on Ubuntu
> A great graphical GUI tool to fit all needs askubuntu.com/a/18459/349837
This script will execute the biggest chunks on the console:
--purge
switch with apt-get
)create a file with this content and give it executable rights:
#!/bin/bash
# Adapted from 71529-ubucleaner.sh - https://web.archive.org/web/20151209182520/http://opendesktop.org/CONTENT/content-files/71529-ubucleaner.sh
OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}')
CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)"
METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"
OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL)
YELLOW="\033[1;33m"; RED="\033[0;31m"; ENDCOLOR="\033[0m"
if [ $USER != root ]; then
echo -e $RED"Error: must be root! Exiting..."$ENDCOLOR
exit 0
fi
echo -e $YELLOW"Cleaning apt ..."$ENDCOLOR
aptitude clean
apt-get autoremove
apt-get autoclean
echo -e $YELLOW"Those packages were uninstalled without --purge:"$ENDCOLOR
echo $OLDCONF
#apt-get purge "$OLDCONF" # fixes the error in the original script
for PKGNAME in $OLDCONF ; do # a better way to handle errors
echo -e $YELLOW"Purge package $PKGNAME"
apt-cache show "$PKGNAME"|grep Description: -A3
apt-get -y purge "$PKGNAME"
done
echo -e $YELLOW"Removing old kernels..."$ENDCOLOR
echo current kernel you are using:
uname -a
aptitude purge $OLDKERNELS
echo -e $YELLOW"Emptying every trashes..."$ENDCOLOR
rm -rf /home/*/.local/share/Trash/*/** &> /dev/null
rm -rf /root/.local/share/Trash/*/** &> /dev/null
echo -e $YELLOW"Script Finished!"$ENDCOLOR
Adapted from 71529-ubucleaner.sh
Some tools that will help you find large folders and packages:
sudo apt install ncdu debian-goodies deborphan
sudo ncdu -xr / # lists all folders by size on the console (like the gui `baobab`)
dpigs -H # shows large packages that you don't use
man deborphan # finds packages that have no packages depending on them
deborphan --guess-all --libdevel | xargs apt-get -s purge
Use localepurge to uninstall unused languages in your system:
sudo apt install localepurge
sudo localepurge
LANG=c snap list --all | awk '/disabled/{print $1, $3}' | \
while read snapname revision; do \
snap remove "$snapname" --revision="$revision"; \
done
More here.
A great graphical GUI tool to fit all needs:
sudo apt install bleachbit
More info about Bleachbit here.
pip cache purge
sudo pip cache purge
ncdu /var/tmp
ncdu /var/cache
Additionally you can remove manpages and documentation as described in the Ubuntu Wiki:
Create a file /etc/dpkg/dpkg.cfg.d/01_nodoc which specifies the desired filters. Example:
path-exclude /usr/share/doc/*
# if we need to keep copyright files for legal reasons:
# path-include /usr/share/doc/*/copyright
path-exclude /usr/share/man/*
path-exclude /usr/share/groff/*
path-exclude /usr/share/info/*
# lintian stuff is small, but really unnecessary
path-exclude /usr/share/lintian/*
path-exclude /usr/share/linda/*
Remove the same set of files and directories in the project-config's postinst. Example:
echo "Removing documentation..."
# if we need to keep copyright files for legal reasons:
# find /usr/share/doc -depth -type f ! -name copyright | xargs rm || true
# else:
find /usr/share/doc -depth -type f | xargs rm || true
rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/* /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*
uname -a
. In case you just did an apt-get ugrade before and got a new kernel, this could be the cause, that the current kurnel you are using is not the newest that is installed? Do a repoot then before starting this script
debfoster
better than deborphan. Also, popcon-largest-unused
. Someone already mentioned kdirstat
and bleachbit
(which IIRC has a dupes finder).
Try using BleachBit (located at sourceforge). It is a great program. the basic idea is that it quickly frees up disk space and removes a lot of the junk that is hidden in the system. There are about 70 applications that it can recognize and wipe clean. There is also the ability to use it to "wipe" the free disk space. I think of it as CCleaner from windows only for linux.
If you use UFW, check the log folder. On one of my machines, UFW was generating 8Gb of logs in a couple of days.
You could also empty the apt cache with:
sudo apt-get clean
First, there is a tool for listing all big folders and files. Just type 'Baobab' into the launcher. By removing folders and files you don't need you get more space.
Then, there is a program for removing double files. The program is called fslint
.
Install it by entering
sudo apt-get install fslint
in a Terminal.
or graphically
You can also clear the package cache with
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get autoremove
The fourth step is to remove old Kernel entries. You can do this by installing and opening Synaptic. In Synaptic, search for the old Kernel entries (every Kernel entry that is displayed in GRUB except the newest) and remove it.
One good step is to remove the application cache. Do this by installing and running bleachbit
:
sudo apt-get install bleachbit
or graphically
Important: Deleted cache cannot be restored!
The last step is to defragment the file system. Do the following for this:
cd $HOME
git clone git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
cd e2fsprogs
./configure
make
With these commands, you download and compile e2fsprogs. (If you or the community has got a better way to install the program, please edit!)
Also make sure that git-core
is installed.
If not, execute:
sudo apt-get install git-core
Now you can run the program with:
cd $HOME/e2fsprogs/misc
./e4defrag /dev/sda1 #defragment /dev/sda1
./e4defrag -v /dev/sda1 # verbose output
./e4defrag -c /dev/sda1 # see overview of fragmentation status
Replace /dev/sda1 with the file system or folder/file you want. Note that for defragmenting a device (such as HDD) you need root privilegs, but not for your own files.
Source (German): here
sudo apt-get install ncdu
If you have already deleted a lot of junk but disk space does not seem cleaned just reboot ubuntu. Or if you don't want to reboot just run command like in similar question.
sudo service rsyslog restart
The /tmp
directory should never be cleaned up manually unless absolutely necessary (ie: a closed application didn't clean-up after itself).
You can search where space might be filling up using the 'du' command; usually places of interest are inside /var
. To name two usual suspects /var/log
and '/var/cache'. Though I've had some users who install a backup utility and never realise that it creates GBs of incremental backups in /var/backup
that build up over a week or month to fill the entire disk space.
You can try clearing the cache and error reports i had about 5 gigs of such junk when i tried this first. I used stacer. You can do it manually also.
sudo apt install stacer
When I need make more free space on servers I use this command. It find all files bigger then 50 MB and "du -h" make better list of files and "sort -n" after pipe make list numericcaly sorted by file size.
find / -size +50M -type f -exec du -h {} \; | sort -n
sudo docker container prune -f && sudo docker image prune -f