Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

15 Answers 15

up vote 17 down vote accepted
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).

share|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
    
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
    
Thank you!. I have atleast 1.1GB of free space. How about using apt-get autoremove? –  user3215 Oct 11 '10 at 14:10
    
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
3  
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. –  RandolphCarter Aug 17 '13 at 8:33

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)

share|improve this answer
    
Thank you and how about apt-get autoclean? –  user3215 Oct 11 '10 at 14:28
    
I also use apt-get autoclean but I forgot to write it. I'll update my comment right now! Thanks! –  DrKenobi Oct 12 '10 at 1:39
    
Running 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. –  Drew Noakes Mar 11 '13 at 0:59
    
Is there an English version of the link? –  Andrew Grimm Apr 19 '13 at 0:29
    
Andrew Grimm, there is no English version of the link. –  DrKenobi May 1 '13 at 22:46
  • 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

or

find / -size +50000 -exec ls -lahg {} \;

share|improve this answer
    
Thanks a lot it's more useful –  user3215 Oct 12 '10 at 0:47
    
+1 for kDirStat –  adamnfish Nov 2 '10 at 18:13
4  
+1 for localepurge –  rubo77 Dec 9 '12 at 20:36
    
+1 for everything. Way more usefulness here than the typical clean / autoclean / autoremove findings. –  Mikhail Jul 15 '13 at 2:05
    
+1 this is the most thorough answer - the first command alone revealed ~40GB of forgotten tmp files :/ –  btk Mar 1 at 3:29

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
share|improve this answer
    
Thank you!. I could free up some space by the command you suggested. –  user3215 Oct 11 '10 at 14:11
    
Were I can find UfW log files ? –  Curious Apprentice May 8 '12 at 13:51

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.

share|improve this answer
    
Thanks! it's a good tool for desktop editions –  user3215 Oct 14 '10 at 5:00

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/  
share|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

share|improve this answer

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!

share|improve this answer

Use ubuntu-tweak to clean.

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

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

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!

share|improve this answer

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.

share|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

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

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

Now you can run the program with:

cd $home
cd e2fsprogs
cd 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

share|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 Jun 9 at 0:15

Check for large numbers of log files too:

sudo du -h /var/log
share|improve this answer
    
handy command which lists the file size and not "number of log files" –  dogmatic69 Jan 18 at 20:42

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

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.
share|improve this answer
uname -r 

( to see yours )

apt-get remove linux-image 3.0.* 

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

share|improve this answer

protected by Braiam Mar 6 at 14:44

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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