June 24, 2015

How to Manage your Hard Drive Space

Overview

This document explains several methods to help you manage your server's hard drive space.

Important:

We strongly recommend that you keep at least 10% of your server's available disk space free.

Examine disk space usage

To determine how much available space exists on your server's file systems, run the following command:
df -h
Note:

The df command returns a table that displays basic information about each mounted file system.
  • The -h argument returns the results in a human-readable format.
The output will resemble the following example:
1
2
3
4
5
6
root@host [/var/log]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/LogVol00  288G  189G   85G  70% /
/dev/sda1              99M   47M   48M  50% /boot
tmpfs                 252M     0  252M   0% /dev/shm
/usr/tmpDSK           485M   11M  449M   3% /tmp
This output displays that the system's main storage device (/dev/mapper/LogVol00) which is mounted in the root (/) directory uses 70% of its available disk space, and contains 85 gigabytes (GB) of free space.

Examine disk space usage by file and directory

To determine which files and directories consume most of your hard drive space, run the following command:
du -sh /
Notes:

  • This command displays the estimated disk space of each file and directory that your root directory (/) contains, in human-readable format.
    • The -s argument returns a summary of your present working directory's contents, but does not return each file and directory's disk usage information individually.
    • The -h argument returns the command's results in human-readable format.
    • The slash (/) argument returns the contents of the root (/) directory.
  • We recommend that you only run this command in off-peak hours to prevent additional load on your server.

The output will resemble the following example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@host [~]# du -sh /
372K   ~
107M   etc
113 G home
253M   lib
20K   LICENSE
2.6M   locale
16K   lost+found
64K   mbox_backup
8.0K   media
8.0K   mnt
418M   opt
0   proc
12M   pub
4.0K   pub-htaccess.txt
648K   templates
14K   tmp
64K   tools
5.4G   /var
The numbers in the left column represent the sizes of the files and directories that the working directory contains, in human-readable format.
In the example above, the /home directory uses the most disk space, with 113 gigabytes (GB). However, that directory likely contains your cPanel accounts. Since you will most likely not remove your users' data, examine the /var directory for disk usage data. To do this, run the following command:
du -sh /var/*
Note:

In the example above, the asterisk (*) wildcard argument that lists the summarized, human-readable disk usage information for every file and directory in the /var directory.
The output will resemble the following example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
12K /var/account
4.0K    /var/aptitude
28K /var/aquota.user
938M    /var/cache
559M    /var/cpanel
4.0K    /var/cvs
24K /var/db
32K /var/empty
8.0K    /var/games
173M    /var/lib
8.0K    /var/local
36K /var/lock
3.7G    /var/log
0   /var/mail
10M /var/named
8.0K    /var/nis
8.0K    /var/opt
44K /var/portsentry
8.0K    /var/preserve
144K    /var/profiles
16K /var/proftpd
16K /var/proftpd.delay
4.0K    /var/proftpd.pid
4.0K    /var/proftpd.scoreboard
8.0K    /var/quota.user
8.0K    /var/racoon
1.2M    /var/run
16M /var/spool
4.0K    /var/state
14K /var/tmp
4.0K    /var/vzquota
44K /var/www
20K /var/yp
The output displays that the /var/logs/ directory uses the most disk space.
Repeat this process to locate more files to remove.

Remove unnecessary files

To clear some disk space, run the rm utility to remove some files from the file system, for example:
Warning:

Exercise caution when you run the rm utility. You cannot recover files or directories that you delete.
rm -f filename
In the example above, filename represents the path to the file or directory to remove. The -f argument forces the file's removal, and the system does notprompt you to confirm that you wish to remove the file. This argument saves time if you use an asterisk (*) as a wildcard to remove multiple files.
For example, to remove an old audit log file, change to the /var/log/audit directory and perform the following steps:
  1. Locate the audit.log file that occupies the most disk space. To do this, run the following command:
    du -sh *

    The output will resemble the following example:
    1
    2
    3
    4
    1.8M   audit.log
    2.1M   audit.log.1
    3.1M   audit.log.2
    5.1M   audit.log.3
  2. Run the following command to remove the audit.log file that occupies the most disk space:
    rm -f audit.log.3
    This command will not return output.
  3. Confirm that the audit.log.3 file no longer exists. To do this, run the following command:
    du -h *
    The output will resemble the following example:
    1
    2
    3
    1.8M   audit.log
    5.1M   audit.log.1
    5.1M   audit.log.2
Repeat this process until you clear enough disk space.

How to Clean Log Files Before You Enable Log Rotation 

0 comments:

Post a Comment