Out of disk space too early

September 8, 2014 5.5k views

My hard disk space has been gobbled up without me really installing much if anything. I had backups enabled and I disabled it before deleting the backups. Could they be sucking up all my disk space? I looked in my log directory and nothing in there is very big. I've done apt-get clean, auto clean, etc.

2 Answers

logrotate is the utility that automatically compresses old log files. You can also configure it to delete older logs. Edit the file /etc/logrotate.d/apache2 It will look like:

/var/log/apache2/*.log {
        rotate 52
        create 640 root adm
                if /etc/init.d/apache2 status > /dev/null ; then \
                    /etc/init.d/apache2 reload > /dev/null; \
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \

Add maxage 14 to delete logs older than two weeks.

Issue the command below to see what folder is using up most space

du -sh /*

That should give a summary of what folder is the largest. It won't be an instant result, give the command time to run.

  • Thanks. It looks like my /var/log directory is 24GB. Inside that it claims apache2 is 24 GB but can't seem to list its contents or change directory into it. The following is the contents of the /var/log directory.

    alternatives.log       dpkg.log.2.gz    pm-powersave.log
    alternatives.log.1     faillog          pm-powersave.log.1
    alternatives.log.2.gz  fontconfig.log   pm-powersave.log.2.gz
    apache2                fsck             samba
    apt                    gpu-manager.log  speech-dispatcher
    auth.log               hp               syslog
    auth.log.1             installer        syslog.1
    auth.log.2.gz          kern.log         syslog.2.gz
    auth.log.3.gz          kern.log.1       syslog.3.gz
    auth.log.4.gz          kern.log.2.gz    syslog.4.gz
    boot.log               kern.log.3.gz    syslog.5.gz
    bootstrap.log          kern.log.4.gz    syslog.6.gz
    btmp                   landscape        syslog.7.gz
    btmp.1                 lastlog          udev
    cups                   lightdm          ufw.log
    dbconfig-common        mysql            ufw.log.1
    dist-upgrade           mysql.err        ufw.log.2.gz
    dmesg                  mysql.log        ufw.log.3.gz
    dmesg.0                mysql.log.1.gz   ufw.log.4.gz
    dmesg.1.gz             mysql.log.2.gz   unattended-upgrades
    dmesg.2.gz             mysql.log.3.gz   upstart
    dmesg.3.gz             mysql.log.4.gz   wtmp
    dmesg.4.gz             mysql.log.5.gz   wtmp.1
    dpkg.log               mysql.log.6.gz   Xorg.0.log
    dpkg.log.1             mysql.log.7.gz   Xorg.0.log.old
  • asb's suggestion is a good one to consider if you're struggling to keep a handle on log files, although a 24GB log file is a bit large…

    What do you mean you can't change directory to it? Is it giving an error?

    What happens when you type

    cd /var/log/apache2
    ls -al

    Perhaps the directory won't let you list the contents unless you're root? If you're on ubuntu that means using sudo

    cd /var/log/apache2
    sudo ls -al

    If you find the file thats massive and want to remove it, remove with the rm command

    rm filename

    Again, you'll need to do this as root, which means using sudo

    sudo rm filename

    Linux doesn't rely on file extensions as much as windows, so sometimes a file will be without an extension, which makes it appear as a directory. This also means you might confuse a directory for a file and try to edit it, wondering why it isn't working. Using ls with some colour can help you with that.

    ls --color

    Directories usually show in dark blue, system links in light blue and files do not have any colour - they just show the standard console colour. Note: the --color command cannot be used as --colour, must be the American spelling.

    Let me know any error messages you have, we'll see if we can work it out :-)

  • I get:
    -bash: cd: /var/log/apache2: Permission denied

    when trying to cd to apache2

  • Weird


    sudo cd /var/log/apache2

    You can append sudo to the start of commands to execute them as an administrator (root). Please be VERY careful about what you start as the root user, it can have massive security implications.

Have another answer? Share your knowledge.