System Administration Guide: Advanced Administration

Chapter 16 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 Information About Files and Disk Space

This table summarizes the commands available for displaying information about file size and disk space.

Command 

Man Page 

Description 

df

df(1M)

Reports the number of free disk blocks and files. 

du

du(1)

Summarizes disk space allocated to each subdirectory. 

find -size

find(1)

Searches recursively through a directory based on the size specified with the -size option.

ls -lh

ls(1)

Lists the size of a file in the power of 1024. 

How to Display Information About Files and Disk Space

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


$ df [directory]  [-h] [-t] [-t]

df

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

directory

Specifies the directory whose file system you want to check.  

-h

Displays disk space in the power of 1024. 

-t

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

Examples—Displaying Information About File Size and Disk Space

In the following example, all the file systems listed are locally mounted except for /usr/dist, which is mounted remotely from the system venus.


$ df
/                  (/dev/dsk/c0t0d0s0 ):  287530 blocks    92028 files
/usr               (/dev/dsk/c0t0d0s6 ): 1020214 blocks   268550 files
/proc              (/proc             ):       0 blocks      878 files
/dev/fd            (fd                ):       0 blocks        0 files
/etc/mnttab        (mnttab            ):       0 blocks        0 files
/var/run           (swap              ):  396016 blocks     9375 files
/tmp               (swap              ):  396016 blocks     9375 files
/opt               (/dev/dsk/c0t0d0s5 ):  381552 blocks    96649 files
/export/home       (/dev/dsk/c0t0d0s7 ):  434364 blocks   108220 files
/usr/dist          (venus:/usr/dist   ):14750510 blocks  2130134 files

In the following example, file system information is displayed in 1024 bytes.


$ df -h
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0t0d0s0      1.9G    58M   1.8G     4%    /
/dev/dsk/c0t0d0s6      2.5G   765M   1.7G     1%    /usr
/proc                    0K     0K     0K     0%    /proc
fd                       0K     0K     0K     0%    /dev/fd
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   2.1G    24K   2.1G     1%    /var/run
swap                   2.1G     0K   2.1G     0%    /tmp
/dev/dsk/c0t0d0s5      1.9G    12M   1.8G     1%    /opt
/dev/dsk/c0t0d0s7      1.9G    10K   1.8G     1%    /export/home

Note –

Although /proc and /tmp are local file systems, they are not UFS file systems. /proc is a PROCFS file system, /var/run and /tmp are TMPFS file systems, and /etc/mnttab is a MNTFS 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/c0t0d0s0 ):   287530 blocks    92028 files
                                  total:   385614 blocks    96832 files
/usr               (/dev/dsk/c0t0d0s6 ):  1020214 blocks   268550 files
                                  total:  2381102 blocks   300288 files
/proc              (/proc             ):        0 blocks      879 files
                                  total:        0 blocks      924 files
/dev/fd            (fd                ):        0 blocks        0 files
                                  total:        0 blocks       72 files
/etc/mnttab        (mnttab            ):        0 blocks        0 files
                                  total:        0 blocks        1 files
/var/run           (swap              ):   396112 blocks     9375 files
                                  total:   396112 blocks     9395 files
/tmp               (swap              ):   396112 blocks     9375 files
                                  total:   396128 blocks     9395 files
/opt               (/dev/dsk/c0t0d0s5 ):   381552 blocks    96649 files
                                  total:   385614 blocks    96832 files
/export/home       (/dev/dsk/c0t0d0s7 ):   434364 blocks   108220 files
                                  total:   434382 blocks   108224 files
/usr/dist          (venus:/usr/dist   ): 14750510 blocks  2130134 files
                                  total: 41225162 blocks  2482176 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 to the directory where the files you want to check are located.

  2. Display the size of the files.


    $ ls [-lh] [-s]

    -l

    Displays a list of files and directories in long format, showing the sizes in bytes. (See the example that follows.) 

    -h

    Scales file and directory sizes into Kbytes, Mbytes, Gbytes, or Terabytes when the file or directory size is larger than 1024 bytes. This option also modifies the output displayed by the -o, -n, -@, and -g options to display file or directory sizes in the new format. For more information, see ls(1).

    -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 the lastlog and messages files are larger than the other files in the /var/adm directory.


$ cd /var/adm
$ ls -lh
total 148
drwxrwxr-x   5 adm      adm          512 Nov 26 09:39 acct/
-rw-------   1 uucp     bin            0 Nov 26 09:25 aculog
drwxr-xr-x   2 adm      adm          512 Nov 26 09:25 exacct/
-r--r--r--   1 root     other       342K Nov 26 13:56 lastlog
drwxr-xr-x   2 adm      adm          512 Nov 26 09:25 log/
-rw-r--r--   1 root     root         20K Nov 26 13:55 messages
drwxr-xr-x   2 adm      adm          512 Nov 26 09:25 passwd/
drwxrwxr-x   2 adm      sys          512 Nov 26 09:39 sa/
drwxr-xr-x   2 root     sys          512 Nov 26 09:49 sm.bin/
-rw-rw-rw-   1 root     bin            0 Nov 26 09:25 spellhist
drwxr-xr-x   2 root     sys          512 Nov 26 09:25 streams/
-rw-r--r--   1 root     bin         3.3K Nov 26 13:56 utmpx
-rw-r--r--   1 root     root           0 Nov 26 10:17 vold.log
-rw-r--r--   1 adm      adm          19K Nov 26 13:56 wtmpx

The following example shows that the lpsched.1 file uses two blocks.


$ cd /var/lp/logs
$ ls -s
total 2            0 lpsched       2 lpsched.1

How to Find Large Files

  1. Change to the directory that 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 largest to smallest. 

Example—Finding Large Files

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


$ cd /var/adm
$ ls -s | sort -nr | more
  48 lastlog
  30 messages
  24 wtmpx
  18 pacct
   8 utmpx
   2 vold.log
   2 sulog
   2 sm.bin/
   2 sa/
   2 passwd/
   2 pacct1
   2 log/
   2 acct/
   0 spellhist
   0 aculog
total 144

How to Find Files That Exceed a Specified Size Limit

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


$ find directory -size +nnn 

directory

Identifies the directory you want to search. 

-size +nnn

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

Example—Finding Files That Exceed a Specified Size Limit

The following example shows how to find files larger 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 options. Additionally, you can find the amount of disk space used by user accounts on local UFS file systems by using the quot command. For more information about these commands, see du(1) 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 the total number of blocks contained in the specified directory. 

-h

Displays the size of each directory in 1024 bytes. 

-H

Displays the size of each directory in 1000 bytes. 

directory ...

Identifies one or more directories you want to check. 

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

The following example shows the total sizes of two directories.


$ du -s /var/adm /var/spool/lp
130     /var/adm
40      /var/spool/lp

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


$ du /var/adm /var/spool/lp
2       /var/adm/log
2       /var/adm/passwd
2       /var/adm/acct/fiscal
2       /var/adm/acct/nite
2       /var/adm/acct/sum
8       /var/adm/acct
2       /var/adm/sa
2       /var/adm/sm.bin
130     /var/adm
4       /var/spool/lp/admins
2       /var/spool/lp/fifos/private
2       /var/spool/lp/fifos/public
6       /var/spool/lp/fifos
2       /var/spool/lp/requests/starbug
4       /var/spool/lp/requests
2       /var/spool/lp/system
2       /var/spool/lp/tmp/starbug
2       /var/spool/lp/tmp/.net/tmp/starbug
4       /var/spool/lp/tmp/.net/tmp
2       /var/spool/lp/tmp/.net/requests/starbug
4       /var/spool/lp/tmp/.net/requests
10      /var/spool/lp/tmp/.net
14      /var/spool/lp/tmp
40      /var/spool/lp

The following example shows directory sizes in 1024 bytes.


du -h /usr/share/audio
 796K   /usr/share/audio/samples/au
 797K   /usr/share/audio/samples
 798K   /usr/share/audio

How to Display the User Ownership of Local UFS File Systems

  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

    Identifies 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 Ownership 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:
43340   root    
 3142   rimmer   
   47   uucp    
   35   lp      
   30   adm     
    4   bin     
    4   daemon  
# quot -a
/dev/rdsk/c0t0d0s0 (/):
43340   root    
 3150   rimmer  
   47   uucp    
   35   lp      
   30   adm     
    4   bin     
    4   daemon  
/dev/rdsk/c0t0d0s6 (/usr):
460651  root    
206632  bin     
  791   uucp    
   46   lp      
    4   daemon  
    1   adm     
/dev/rdsk/c0t0d0s7 (/export/home):
    9   root    

Finding and Removing Old or 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 crash dump files, refer to Chapter 28, Managing System Crash Information (Tasks).

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 files by latest time stamp first. 

directory

Identifies the directory you want to search. 

Example—Listing the Newest Files

The following example shows how to use the ls -tl command to locate the most recently created or changed files within the /var/adm directory. The sulog file was created or edited most recently.


$ ls -tl /var/adm
total 134
-rw-------   1 root     root         315 Sep 24 14:00 sulog
-r--r--r--   1 root     other     350700 Sep 22 11:04 lastlog
-rw-r--r--   1 root     bin         4464 Sep 22 11:04 utmpx
-rw-r--r--   1 adm      adm        20088 Sep 22 11:04 wtmpx
-rw-r--r--   1 root     other          0 Sep 19 03:10 messages
-rw-r--r--   1 root     other          0 Sep 12 03:10 messages.0
-rw-r--r--   1 root     root       11510 Sep 10 16:13 messages.1
-rw-r--r--   1 root     root           0 Sep 10 16:12 vold.log
drwxr-xr-x   2 root     sys          512 Sep 10 15:33 sm.bin
drwxrwxr-x   5 adm      adm          512 Sep 10 15:19 acct
drwxrwxr-x   2 adm      sys          512 Sep 10 15:19 sa
-rw-------   1 uucp     bin            0 Sep 10 15:17 aculog
-rw-rw-rw-   1 root     bin            0 Sep 10 15:17 spellhist
drwxr-xr-x   2 adm      adm          512 Sep 10 15:17 log
drwxr-xr-x   2 adm      adm          512 Sep 10 15:17 passwd

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

    Identifies the directory you want to search. Directories below this directory are also searched. 

    -atime +nnn

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

    -mtime +nnn

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

    filename

    Identifies the file that contains the list of inactive files. 

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


    # rm `cat filename`
    

    filename identifies the file created in the previous step which contains the list of inactive files.

Example—Finding and Removing Old or Inactive Files

The following example shows files in the /var/adm directory and the subdirectories that have not been accessed in the last 60 days. The /var/tmp/deadfiles file contains the list of inactive files. The rm command removes these inactive files.


# find /var/adm -type f -atime +60 -print > /var/tmp/deadfiles &
# more /var/tmp/deadfiles
/var/adm/aculog
/var/adm/spellhist
/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 directory to clean out.


    # cd directory
    

    Caution – Caution –

    Be sure you are in the right directory before completing step 3. Step 3 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 unnecessary temporary or obsolete subdirectories and files, and delete them by repeating Step 3.

Example—Clearing Out Temporary Directories

The following example shows how to clear out the mywork directory, and how to verify that all files and subdirectories were removed.


# cd mywork
# ls
filea.000
fileb.000
filec.001
# rm -r *
# ls
#

How to Find and Delete core Files

  1. Become superuser.

  2. Change to the directory where you want to search for core files.

  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 jones user account by 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
    

    Where system identifies a system that created the crash dump files.


    Caution – Caution –

    Be sure you are in the right directory before completing step 3. Step 3 deletes all files in the current directory.


  3. Remove the crash dump files.


    # rm *
    
  4. Verify that 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 *
# ls