System Administration Guide

Chapter 57 Managing Disk Use (Tasks)

This chapter describes how to optimize disk space by locating unused files and large directories. This is a list of the step-by-step instructions in this chapter.

Displaying Blocks and Files Used

Use the df command and its options to report the number of free disk blocks and files. For more information, see df(1M).

How to Display Information About Blocks, Files, and Disk Space

Display information about how disk space is used by using the df command.


$ df [directory] [-F fstype] [-g] [-k] [-t]

df

With no options, lists all mounted file systems and their device names, the number of total 512-byte blocks used, and the number of files. 

directory

Directory whose file system you want to check. The device name, blocks used, and number of files are displayed. 

-F fstype

Displays a list of unmounted file systems, their device names, the number of 512-byte blocks used, and the number of files on file systems of type fstype.

-g

Displays the statvfs structure for all mounted file systems.

-k

Displays a list of file systems, kilobytes used, free kilobytes, percent capacity used, and mount points. 

-t

Displays total blocks as well as blocks used for all mounted file systems. 


Note -

For remotely mounted file systems, "-1 files"is displayed instead of the number of files.


Examples--Displaying Information About Blocks, Files, and Disk Space

In the following example, the file systems root (/), /usr, /proc, and /tmp are on the local disk. The other file systems are mounted by NFS and do not use local disk resources.


$ df
/               (/dev/dsk/c0t3d0s0 ):   30374 blocks    14002 files
/usr            (/dev/dsk/c0t3d0s6 ):   40714 blocks    80522 files
/proc           (/proc             ):       0 blocks      429 files
/dev/fd         (fd                ):       0 blocks        0 files
/export/home    (/dev/dsk/c0t3d0s7 ):   10712 blocks    10564 files
/export/root    (/dev/dsk/c0t3d0s3 ):   69180 blocks    18812 files
/export/swap    (/dev/dsk/c0t3d0s4 ):   61804 blocks    29563 files
/opt            (/dev/dsk/c0t3d0s5 ):   15722 blocks    13147 files
/tmp            (swap              ):   57104 blocks     5653 files
/usr/local      (mars:/usr/local   ):  435040 blocks       -1 files
$

In the following example, the file system, total Kbytes, used Kbytes, available Kbytes, percent of capacity used, and mount point are displayed.


$ df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t3d0s0      30991   15812   12089    57%    /
/dev/dsk/c0t3d0s6     185303  164946    1827    99%    /usr
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
/dev/dsk/c0t3d0s7      19095   13739    3456    80%    /export/home
/dev/dsk/c0t3d0s3      34599       9   31140     1%    /export/root
/dev/dsk/c0t3d0s4      55511   24609   25352    50%    /export/swap
/dev/dsk/c0t3d0s5      23063   15202    5561    74%    /opt
swap                   29564     976   28588     4%    /tmp
mars:/usr/local      5353093 5135591  163972    97%    /usr/local
$

The following example shows information about the same system as the previous example, but only UFS file system information is displayed.


$ df -F ufs
/             (/dev/dsk/c0t3d0s0 ):   30358 blocks    14002 files
/usr          (/dev/dsk/c0t3d0s6 ):   40714 blocks    80522 files
/export/home  (/dev/dsk/c0t3d0s7 ):   10712 blocks    10564 files
/export/root  (/dev/dsk/c0t3d0s3 ):   69180 blocks    18812 files
/export/swap  (/dev/dsk/c0t3d0s4 ):   61804 blocks    29563 files
/opt          (/dev/dsk/c0t3d0s5 ):   15722 blocks    13147 files
$

Note -

Although /proc and /tmp are local file systems, they are not UFS file systems (/proc is a PROCFS file system, and /tmp is a TMPFS file system).


The following example shows a list of all mounted file systems, device names, total 512-byte blocks used, and number of files. The second line of each two-line entry displays the total number of blocks and files allocated for the file system.


$ df -t
/             (/dev/dsk/c0t3d0s0 ):    30358 blocks    14002 files
                             total:    61982 blocks    16128 files
/usr          (/dev/dsk/c0t3d0s6 ):    40714 blocks    80522 files
                             total:   370606 blocks    94080 files
/proc         (/proc             ):        0 blocks      429 files
                             total:        0 blocks      492 files
/dev/fd       (fd                ):        0 blocks        0 files
                             total:        0 blocks       26 files
/export/home  (/dev/dsk/c0t3d0s7 ):    10712 blocks    10564 files
                             total:    38190 blocks    10752 files
/export/root  (/dev/dsk/c0t3d0s3 ):    69180 blocks    18812 files
                             total:    69198 blocks    18816 files
/export/swap  (/dev/dsk/c0t3d0s4 ):    61804 blocks    29563 files
                             total:   111022 blocks    29568 files
/opt          (/dev/dsk/c0t3d0s5 ):    15722 blocks    13147 files
                             total:    46126 blocks    13440 files
/tmp          (swap              ):    57144 blocks     5653 files
                             total:    59096 blocks     5768 files
/usr/local    (mars:/usr/local   ):   435008 blocks       -1 files
                             total: 10706186 blocks       -1 files
$

Checking the Size of Files

You can check the size of files and sort them by using the ls command. You can find files that exceed a size limit by using the find command. For more information, see ls(1) and find(1).

How to Display the Size of Files

  1. Change the directory to where the files you want to check are located.

  2. Display the size of the files.


    $ ls [-l] [-s]

    -l

    Displays a list of files and directories in long format, showing the sizes in bytes. 

    -s

    Displays a list of the files and directories, showing the sizes in blocks. 

Examples--Displaying the Size of Files

The following example shows that lastlog, wtmp, and wtmpx are substantially larger than the other files in the /var/adm directory.


venus% cd /var/adm
venus% ls -l
total 434
-r--r--r--   1 root     other     585872 Jan 28 14:53 lastlog
drwxrwxr-x   2 adm      adm          512 Dec  1 16:35 log
-rw-r--r--   1 root     other        408 Jan 28 14:15 messages
-rw-r--r--   1 root     other        177 Jan 24 16:56 messages.0
-rw-r--r--   1 root     other        177 Jan 17 16:13 messages.1
-rw-r--r--   1 root     other          0 Jan  4 04:05 messages.2
-rw-r--r--   1 root     other        562 Jan  2 13:13 messages.3
drwxrwxr-x   2 adm      adm          512 Dec  1 16:35 passwd
drwxrwxr-x   2 adm      sys          512 Jan 28 11:38 sa
-rw-rw-rw-   1 bin      bin            0 Nov 26 10:56 spellhist
-rw-------   1 root     root        1319 Jan 28 14:58 sulog
-rw-r--r--   1 root     bin          288 Jan 28 14:53 utmp
-rw-r--r--   1 root     bin         2976 Jan 28 14:53 utmpx
-rw-rw-r--   1 adm      adm        12168 Jan 28 14:53 wtmp
-rw-rw-r--   1 adm      adm       125736 Jan 28 14:53 wtmpx

The following example shows that lpNet uses eight blocks and lpsched and lpsched-1 use two blocks each.


% cd /var/lp/logs
% ls -s
total 14            2 lpsched-1    0 lpsched-4      0 requests-2
   8 lpNet          2 lpsched-2    0 requests
   2 lpsched        0 lpsched-3    0 requests-1
%

How to Find Large Files

  1. Change directory to the location where you want to search.

  2. Display the size of files in blocks from largest to smallest.


    $ ls -s | sort -nr | more
    

    sort -nr

    Sorts the list of files by block size from smallest to largest. 

Example--Finding Large Files

In the following example, wtmpx and lastlog are the largest files in the /var/adm directory.


$ cd /var/adm
$ ls -s | sort -nr | more
 320 wtmpx
 128 lastlog
  74 pacct
  56 messages
  30 wtmp
   6 utmpx
   2 utmp
   2 sulog
   2 sa
   2 passwd
   2 log
   0 spellhist
total 624

How to Find Files That Exceed a Given Size Limit

To locate and display the names of files that exceed a specified size, use the find command.


$ find directory -size +nnn 

directory

Directory you want to search. 

--size +nnn

Is a number of 512-byte blocks. Files that exceed the size indicated are listed. 

Example--Finding Files That Exceed a Given Size Limit

The following example shows how to find files with more than 400 blocks in the current working directory.


$ find . -size +400 -print
./Howto/howto.doc
./Howto/howto.doc.backup
./Howto/howtotest.doc
./Routine/routineBackupconcepts.doc
./Routine/routineIntro.doc
./Routine/routineTroublefsck.doc
./.record
./Mail/pagination
./Config/configPrintadmin.doc
./Config/configPrintsetup.doc
./Config/configMailappx.doc
./Config/configMailconcepts.doc
./snapshot.rs

Checking the Size of Directories

You can display the size of directories by using the du command and its options. Additionally, you can find the amount of disk space taken up by user accounts on local UFS file systems by using the quot command. For more information about these commands, see du(1M)and quot(1M).

How to Display the Size of Directories, Subdirectories, and Files

Display the size of one or more directories, subdirectories, and files by using the du command. Sizes are displayed in 512-byte blocks.


$ du [-as] [directory ...]

du

Displays the size of each directory you specify, including each subdirectory beneath it. 

-a

Displays the size of each file and subdirectory, and the total number of blocks contained in the specified directory. 

-s

Displays only the total number of blocks contained in the specified directory. 

directory ...

Specifies one or more directories you want to check. 

Examples--Displaying the Size of Directories, Subdirectories, and Files

The following example displays the sizes of two directories and all the subdirectories they contain.


$ du /var/log /var/cron
4       /var/log
3250    /var/cron

The following example displays the sizes of two directories, all of the subdirectories and files they contain, and the total number of blocks contained in each directory.


$ du -a /var/log /var/cron
0       /var/log/authlog
0       /var/log/syslog
2       /var/log/sysidconfig.log
4       /var/log
3248    /var/cron/log
3250    /var/cron

The following example displays the total sizes of two directories.


$ du -s /var/log /var/cron
4      /var/log
3250   /var/cron

How to Display the User Allocation of Local UFS File System

  1. Become superuser.

  2. Display users, directories, or file systems, and the number of 1024-byte blocks used.


    # quot [-a] [filesystem]

    -a

    Lists all users of each mounted UFS file system and the number of 1024-byte blocks used. 

    filesystem

    Is a UFS file system. Users and the number of blocks used are displayed. 


    Note -

    The quot command works only on local UFS file systems.


Example--Displaying the User Allocation of Local UFS File Systems

In the following example, users of the root (/) file system are displayed, then users of all mounted UFS file systems are displayed.


# quot /
/dev/rdsk/c0t0d0s0:
35400   bin
14312   smtp
  183   adm
   49   lp
   47   uucp
   37   bob
   28   sys
    2   mary
# quot -a
/dev/rdsk/c0t0d0s0 (/):
35400   bin
14312   smtp
  183   adm
   49   lp
   47   uucp
   37   bob
   28   sys
    2   mary
/dev/rdsk/c0t0d0s6 (/usr):
104276  smtp
56567   bin
 2000   lp
  698   uucp
    1   adm
/dev/rdsk/c0t0d0s7 (/export/home):
  617   smtp

Finding and Removing Old and Inactive Files

Part of the job of cleaning up heavily loaded file systems involves locating and removing files that have not been used recently. You can locate unused files using the ls or find commands. For more information, see ls(1) and find(1).

Other ways to conserve disk space include emptying temporary directories such as the ones located in /var/tmp or /var/spool, and deleting core and crash dump files. For more information about these files, refer to Chapter 69, Generating and Saving System Crash Information.

How to List the Newest Files

List files, displaying the most recently created or changed files first, by using the ls -t command.


$ ls -t [directory]

-t  

Sorts listings by latest time stamp first. 

directory

Directory you want to search. 

Example--Listing the Newest Files

The following example shows how to use ls -t to locate the most recent files within the /var/adm directory. sulog, messages, utmpx, wtmpx, utmp, and lastlog were created or edited most recently. This is verified using output from ls -l, which shows that these three files were created or edited in March, while the other files in /var/spool were created or edited earlier.


$ ls -t /var/adm
sulog      wtmpx        wtmp        messages.1  vold.log   spellhist
messages   utmp         sa          messages.2  log        aculog
utmpx      lastlog      messages.0  messages.3  acct       passwd
$ ls -l /var/adm
total 686
drwxr-xr-x  5 adm       adm         512 Feb 13 16:20 acct
-rw-------  1 uucp      bin           0 Feb 13 16:04 aculog
-r--r--r--  1 root      other      8456 Mar 27 10:34 lastlog
drwxr-xr-x  2 adm       adm         512 Feb 13 16:36 log
-rw-r--r--  1 root      other    117376 Mar 27 13:11 messages
-rw-r--r--  1 root      other      4620 Jan 30 08:30 messages.0
-rw-r--r--  1 root      other     11176 Jan 23 04:30 messages.1
-rw-r--r--  1 root      other        60 Jan 13 09:45 messages.2
-rw-r--r--  1 root      other         0 Jan 31 04:05 messages.3
drwxr-xr-x  2 adm       adm         512 Feb 13 16:03 passwd
drwxr-xr-x  2 adm       sys         512 Mar 20 06:59 sa
-rw-rw-rw-  1 bin       bin           0 Feb 13 16:04 spellhist
-rw-------  1 root      root       1647 Mar 27 13:28 sulog
-rw-r--r--  1 root      bin         504 Mar 27 10:34 utmp
-rw-r--r--  1 root      bin        5208 Mar 27 10:34 utmpx
-rw-rw-rw-  1 root      root        500 Jan 11 14:40 vold.log
-rw-rw-r--  1 adm       adm       14724 Mar 27 10:34 wtmp
-rw-rw-r--  1 adm       adm      151404 Mar 27 10:34 wtmpx

How to Find and Remove Old or Inactive Files

  1. Become superuser.

  2. Find files that have not been accessed for a specified number of days and list them in a file.


    # find directory  -type f [-atime +nnn] [-mtime +nnn] -print > filename
    

    directory

    Directory you want to check. Directories below this also will be checked. 

    -atime +nnn

    Finds files that have not been accessed within the number of days you specify. 

    -mtime +nnn

    Finds files that have not been modified within the number of days you specify. 

    filename

    File containing the list of inactive files.

  3. Remove the inactive files that you listed in the previous step.


    # rm `cat filename`
    

    filename

    File created by this command which contains the list of inactive files. 

Example--Finding and Removing Old or Inactive Files

The following example locates regular files in /var/adm and its directories that have not been accessed in the last 60 days and saves the list of inactive files in /var/tmp/deadfiles. These files are then removed with the rm command.


# find /var/adm -type f -atime +60 -print > /var/tmp/deadfiles &
# more /var/tmp/deadfiles
/var/adm/log/asppp.log
/var/adm/aculog
/var/adm/spellhist
/var/adm/wtmp
/var/adm/wtmpx
/var/adm/sa/sa13
/var/adm/sa/sa27
/var/adm/sa/sa11
/var/adm/sa/sa23
/var/adm/sulog
/var/adm/vold.log
/var/adm/messages.1
/var/adm/messages.2
/var/adm/messages.3
# rm `cat /var/tmp/deadfiles`

How to Clear Out Temporary Directories

  1. Become superuser.

  2. Change to the /var/tmp directory.


    # cd /var/tmp
    

    Caution - Caution -

    Be sure you are in the right directory before completing the following step. The next step deletes all files in the current directory.


  3. Delete the files and subdirectories in the current directory.


    # rm -r *
    
  4. Change to other directories containing temporary or obsolete subdirectories and files (for example, mail, lost+found, or quotas), and delete them by repeating Step 3 above.

Example--Clearing Out Temporary Directories

The following example shows how to clear out the /var/tmp directory, and verifies that all files and subdirectories were removed.


# cd /var/tmp
# ls
deadfiles           wxconAAAa0003r:0.0  wxconAAAa000NA:0.0
test_dir            wxconAAAa0003u:0.0  wxconAAAa000cc:0.0 
wxconAAAa000zs:0.0
# rm -r *
# ls
#

How to Find and Delete core Files

  1. Become superuser.

  2. Change the directory to where you want to start the search.

  3. Find and remove any core files in this directory and its subdirectories.


    # find . -name core -exec rm {} \;
    

Example--Finding and Deleting core Files

The following example shows how to find and remove core files from the user account belonging to jones using the find command.


# cd /home/jones
# find . -name core -exec rm {} \;
 

How to Delete Crash Dump Files

Crash dump files can be very large, so if you have enabled your system to store these files, do not retain them for longer than necessary.

  1. Become superuser.

  2. Change to the directory where crash dump files are stored.


    # cd /var/crash/system
    

    system

    System that created the crash dump files. 


    Caution - Caution -

    Be sure you are in the right directory before completing the following step. The next step deletes all files in the current directory.


  3. Remove the crash dump files.


    # rm *
    
  4. Verify the crash dump files are removed.


    # ls
    

Example--Deleting Crash Dump Files

The following example shows how to remove crash dump files from the system venus, and how to verify that the crash dump files were removed.


# cd /var/crash/venus
# rm *
#