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.

  • 1
    Try this one too: dpkg -l | grep ^rc | cut -d ' ' -f3 | xargs sudo apt-get purge -y – crsuarezf Nov 13 '15 at 22:07
  • If you are using docker: docs.docker.com/config/pruning – Gerard Carbó Dec 10 '18 at 9:14
  • for many cases: sudo docker container prune -f && sudo docker image prune -f – smftr Jun 25 '19 at 7:36

18 Answers 18

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).

| improve this answer | |
  • will it not affect running applications like if it removes any necessary package on which any application depends?. – user3215 Oct 11 '10 at 13:54
  • 1
    No. Autoremove looks for orphaned packages, that is to say packages that you didn't explicitly install yourself (ones marked auto) and that have no dependencies. If you use 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. – Oli Oct 11 '10 at 14:03
  • 1
    Typo in my last comment. I meant to say that orphaned packages are ones that aren't depended on, not ones that "have no dependencies". They may well have dependencies and if they were only there for that orphaned package, they'll be removed too. Some times (with really deep dependency trees) it can take a couple of autoremoves to clean up. – Oli Oct 11 '10 at 14:28
  • 5
    While the above command is certainly useful, it will not, as stated, remove old kernels. That has to be done either manually or with additional tools like Ubuntu Tweak. – codeling Aug 17 '13 at 8:33
  • 1
    @nyarlathotep It will remove kernel header files, which at first glance may make one think it's removing the old kernels - the old kernels remain, however (try dpkg --get-selections | grep linux-image). – drevicko Dec 1 '13 at 23:55

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)

| improve this answer | |
  • show top 10 biggest subdirs in the current dir.

    du -sk * | sort -nr | head -10
  • use filelight or kDirStat to see where the disk space is going visually

  • check if you have old kernels for deletion

    ls -lh /boot
  • cleaning packages

    sudo apt-get autoremove
    sudo apt-get 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-get install localepurge
  • check content of /var/tmp/

    du -sh /var/tmp/
  • check also

    man deborphan
  • Search for big files:

    find / -type f -size +1024k


    find / -size +50000  -exec ls -lahg {} \;
  • big installed packages


this is part of the package: debian-goodies

| improve this answer | |
  • 5
    To find big files I suggest ncdu, which provides a fast way to see what directories are using your disk space – rubo77 Jan 22 '15 at 5:18
  • 2
    kDirStat is replaced by baobab – rubo77 Jan 22 '15 at 6:23

I just freed up almost 2 gigs by removing old kernels and header files:


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!

| improve this answer | |
  • That bit about wildcards ? Before making use of it I would double-check that because I tried it and I got more than I wanted. It's possible (perhaps even likely) that I stuffed up in some way but I don't know how and yet I lost more headers than I wanted . – glaucon Oct 25 '16 at 21:28
  • The wildcards are regex wildcards rather than globs. – Chai T. Rex Sep 24 '18 at 15:04

Do not forget to Empty Trash.

enter image description here

Or from command line:

rm -r ~/.local/share/Trash/info/ && rm -r ~/.local/share/Trash/files/  
| improve this answer | |

I really recommend you the program BleachBit, which cleans everything on Ubuntu.

Install it using the following command:

sudo apt-get install bleachbit

| improve this answer | |

Remove all old kernel versions automatically

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!

| improve this answer | |

Uninstall large packages that you don't use

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


$ 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.
| improve this answer | |

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
| improve this answer | |
  • handy command which lists the file size and not "number of log files" – dogmatic69 Jan 18 '14 at 20:42
  • or use sudo ncdu /var/log – rubo77 Jan 22 '15 at 5:20
  • @rubo77, thanks, that's a really nice tool! – Drew Noakes Jan 22 '15 at 12:42

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
| improve this answer | |

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.

| improve this answer | |
  • 3
    Note that the question specifically asks for server tools and this is a desktop program (requires X display). – Ryre May 6 '15 at 14:59
  • Best tool till now! – Roger Mar 4 '17 at 16:41

cleaner script

This script will execute the biggest chunks on the console:

  • Clean apt cache
  • Remove config files left from uninstalled .deb packages (happens if you don't use the --purge switch with apt-get)
  • Remove every kernel except the one you are using
  • Empty the trashes of every user(including root)

create a file with this content and give it executable rights:

# Adapted from 71529-ubucleaner.sh - http://www.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')
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

echo -e $YELLOW"Cleaning apt ..."$ENDCOLOR
aptitude clean
apt-get autoremove
apt-get autoclean

echo -e $YELLOW"Those packages were uninstalled without --purge:"$ENDCOLOR
#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"

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

find large folders and packages

Some tools that will help you find large folders and packages:

sudo apt-get install ncdu debian-goodies deborphan

sudo ncdu /    # 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-get install localepurge

remove old snapd images

LANG=c snap list --all | awk '/disabled/{print $1, $3}' | \
    while read snapname revision; do \
        snap remove "$snapname" --revision="$revision"; \


A great graphical GUI tool to fit all needs:

sudo apt-get install bleachbit

remove manpages and documentation

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/*
| improve this answer | |

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

Install fslint via the software center

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

Install bleachbit via the software center

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

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 

or using Software Center Install git-core via the software center

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

| improve this answer | |
  • Wow, deleting old linux-header and linux-image versions freed up about a gig and a half on my 10.04 install. fslint is a great find as well. Thanks. – braddock Jul 15 '12 at 23:13
  • Instead of baobab you can also use the commandline tool ncdu to find large folders and files: sudo apt-get install ncdu – rubo77 Jan 22 '15 at 5:19

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.

| improve this answer | |
  • Thank you!. As you said I have some space occupied in MBs under /var/cache and wondering how to remove unnecessary files. – user3215 Oct 11 '10 at 14:13

Use ubuntu-tweak to clean.

it cleans all *.deb that are downloaded to installation apps.

| improve this answer | |
  • not working with KDE – rubo77 Oct 29 '13 at 8:10

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
| improve this answer | |

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
| improve this answer | |
  • 1
    You'd be better off dust using ncdu / instead – rubo77 Feb 3 '15 at 13:34
  • 1
    Given du -h, use sort -h as well. – muru Feb 3 '15 at 13:56
uname -r 

( to see yours )

apt-get remove linux-image 3.0.* 

( yours older versions ). It gave me 600mb freed space.

| improve this answer | |
  • 3
    Downvoted because with commands like this one if you are not careful you can remove the latest kernel (or even all kernels). – ndemou Feb 11 '15 at 20:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.