System Administration Guide: Advanced Administration

Chapter 6 Managing Disk Use (Tasks)

This chapter describes how to optimize disk space by locating unused files and large directories.

For information on the procedures associated with managing disk use, see Managing Disk Use (Task Map).

Managing Disk Use (Task Map)

Task 

Description 

For Instructions 

Display information about files and disk space. 

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

How to Display Information About Files and Disk Space

Display the size of files. 

Display information about the size of files by using the ls command with the -lh option.

How to Display the Size of Files

Find large files. 

The ls -s command allows you to sort files by size, in descending order.

How to Find Large Files

Find files that exceed a specified size limit. 

Locate and display the names of files that exceed a specified size by using the find command with the -size option and the value of the specified size limit.

How to Find Files That Exceed a Specified Size Limit

Display the size of directories, subdirectories, and files. 

Display the size of one or more directories, subdirectories, and files by using the du command.

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

Display ownership of local UFS file systems. 

Display ownership of files by using the quot -a command.

How to Display the User Ownership of Local UFS File Systems

List the newest files. 

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

How to List the Newest Files

Find and remove old or inactive files. 

Use the find command with the -atime and -mtime options to locate files that have not been accessed for a specified number of days. You can remove these files by using therm `cat filename' command.

How to Find and Remove Old or Inactive Files

Clear out temporary directories. 

Locate temp directories, then use the rm -r * command to remove the entire directory.

How to Clear Out Temporary Directories

Find and delete core files. 

Find and delete core files by using the find . -name core -exec rm {} \; command.

How to Find and Delete core Files

Delete crash dump files. 

Delete crash dump files that are located in the /var/crash/ directory by using the rm * command.

How to Delete Crash Dump Files

Displaying Information About Files and Disk Space

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

Command 

Description 

Man Page 

df

Reports the number of free disk blocks and files 

df(1M)

du

Summarizes disk space allocated to each subdirectory 

du(1)

find -size

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

find(1)

ls -lh

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

ls(1)

ProcedureHow to Display Information About Files and Disk Space

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


    $ df [directory]  [-h] [-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 scaling.

    -t

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


Example 6–1 Displaying Information About File Size and Disk Space

In the following example, all the file systems listed are locally mounted except for /usr/dist.


$ df
/                  (/dev/dsk/c0t0d0s0 ):  101294 blocks   105480 files
/devices           (/devices          ):       0 blocks        0 files
/system/contract   (ctfs              ):       0 blocks 2147483578 files
/proc              (proc              ):       0 blocks     1871 files
/etc/mnttab        (mnttab            ):       0 blocks        0 files
/etc/svc/volatile  (swap              ):  992704 blocks    16964 files
/system/object     (objfs             ):       0 blocks 2147483530 files
/usr               (/dev/dsk/c0t0d0s6 ):  503774 blocks   299189 files
/dev/fd            (fd                ):       0 blocks        0 files
/var/run           (swap              ):  992704 blocks    16964 files
/tmp               (swap              ):  992704 blocks    16964 files
/opt               (/dev/dsk/c0t0d0s5 ):   23914 blocks     6947 files
/export/home       (/dev/dsk/c0t0d0s7 ):   16810 blocks     7160 files


Example 6–2 Displaying File Size Information in 1024 Bytes on a System With a UFS Root File System

In the following example, file system information for a system with a UFS root file system is displayed in 1024 bytes.


$ df -h
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0t0d0s0      249M   200M    25M    90%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   485M   376K   485M     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
/dev/dsk/c0t0d0s6      3.2G   2.9G   214M    94%    /usr
fd                       0K     0K     0K     0%    /dev/fd
swap                   485M    40K   485M     1%    /var/run
swap                   485M    40K   485M     1%    /tmp
/dev/dsk/c0t0d0s5       13M   1.7M    10M    15%    /opt
/dev/dsk/c0t0d0s7      9.2M   1.0M   7.3M    13%    /export/home

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 an MNTFS file system.



Example 6–3 Displaying File Size Information in 1024 Bytes on a System With a ZFS Root File System

In the following example, file system information for a system with a Oracle Solaris ZFS root file system is displayed in 1024 bytes.


Filesystem             size   used  avail capacity  Mounted on
rpool/ROOT/s1008be      67G   4.6G    58G     8%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   1.9G   1.5M   1.9G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap1.so.1
                        63G   4.6G    58G     8% /platform/sun4u-us3/lib/libc_psr.so.1
/platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwcap1.so.1
                        63G   4.6G    58G     8% /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1
fd                       0K     0K     0K     0%    /dev/fd
rpool/ROOT/s1008be/var
                        67G    73M    58G     1%    /var
swap                   1.9G    32K   1.9G     1%    /tmp
swap                   1.9G    40K   1.9G     1%    /var/run
rpool/export            67G    20K    58G     1%    /export
rpool/export/home       67G    18K    58G     1%    /export/home


Example 6–4 Displaying Total Number of Blocks and Files Allocated for a File System

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


$ df -t
/                  (/dev/dsk/c0t0d0s0 ):   101294 blocks   105480 files
                                  total:   509932 blocks   129024 files
/devices           (/devices          ):        0 blocks        0 files
                                  total:        0 blocks      113 files
/system/contract   (ctfs              ):        0 blocks 2147483578 files
                                  total:        0 blocks       69 files
/proc              (proc              ):        0 blocks     1871 files
                                  total:        0 blocks     1916 files
/etc/mnttab        (mnttab            ):        0 blocks        0 files
                                  total:        0 blocks        1 files
/etc/svc/volatile  (swap              ):   992608 blocks    16964 files
                                  total:   993360 blocks    17025 files
/system/object     (objfs             ):        0 blocks 2147483530 files
                                  total:        0 blocks      117 files
/usr               (/dev/dsk/c0t0d0s6 ):   503774 blocks   299189 files
                                  total:  6650604 blocks   420480 files
/dev/fd            (fd                ):        0 blocks        0 files
                                  total:        0 blocks       31 files
/var/run           (swap              ):   992608 blocks    16964 files
                                  total:   992688 blocks    17025 files
/tmp               (swap              ):   992608 blocks    16964 files
                                  total:   992688 blocks    17025 files
/opt               (/dev/dsk/c0t0d0s5 ):    23914 blocks     6947 files
                                  total:    27404 blocks     7168 files
/export/home       (/dev/dsk/c0t0d0s7 ):    16810 blocks     7160 files
                                  total:    18900 blocks     7168 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 the ls(1) and find(1) man pages.


Note –

If you run out of space in the /var directory, do not symbolically link the /var directory to a directory on a file system with more disk space. Doing so, even as a temporary measure, might cause problems for certain daemon processes and utilities.


ProcedureHow 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 sizes and directory sizes into Kbytes, Mbytes, Gbytes, or Tbytes 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 thels(1) man page.

    -s

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


Example 6–5 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

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

    • If the characters or columns for the files are different, use the following command to sort a list of files by block size, from largest to smallest.


      $ ls -l | sort +4rn | more
      

      Note that this command sorts files in a list by the character that is in the fourth field, starting from the left.

    • If the characters or columns for the files are the same, use the following command to sort a list of files by block size, from largest to smallest.


      $ ls -s | sort -nr | more
      

      Note that this command sorts files in a list, starting with the left most character.


Example 6–6 Finding Large Files (Sorting by the Fifth Field's Character)


$ cd /var/adm
$ ls -l | sort +4rn | more
-r--r--r--   1 root     root     4568368 Oct 17 08:36 lastlog
-rw-r--r--   1 adm      adm       697040 Oct 17 12:30 pacct.9
-rw-r--r--   1 adm      adm       280520 Oct 17 13:05 pacct.2
-rw-r--r--   1 adm      adm       277360 Oct 17 12:55 pacct.4
-rw-r--r--   1 adm      adm       264080 Oct 17 12:45 pacct.6
-rw-r--r--   1 adm      adm       255840 Oct 17 12:40 pacct.7
-rw-r--r--   1 adm      adm       254120 Oct 17 13:10 pacct.1
-rw-r--r--   1 adm      adm       250360 Oct 17 12:25 pacct.10
-rw-r--r--   1 adm      adm       248880 Oct 17 13:00 pacct.3
-rw-r--r--   1 adm      adm       247200 Oct 17 12:35 pacct.8
-rw-r--r--   1 adm      adm       246720 Oct 17 13:15 pacct.0
-rw-r--r--   1 adm      adm       245920 Oct 17 12:50 pacct.5
-rw-r--r--   1 root     root      190229 Oct  5 03:02 messages.1
-rw-r--r--   1 adm      adm       156800 Oct 17 13:17 pacct
-rw-r--r--   1 adm      adm       129084 Oct 17 08:36 wtmpx


Example 6–7 Finding Large Files (Sorting by the Left Most Character)

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

ProcedureHow to Find Files That Exceed a Specified Size Limit

  1. 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 that you want to search.

    -size +nnn

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


Example 6–8 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. The -print option displays the output of the find command.


$ 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 the du(1) and quot(1M) man pages.

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

  1. 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 that you specify, including each subdirectory beneath it.

    -a

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

    -s

    Displays the total number of blocks that are contained in the specified directory.

    -h

    Displays the size of each directory in 1024–byte blocks.

    -H

    Displays the size of each directory in 1000–byte blocks.

    [directory ...]

    Identifies one or more directories that you want to check. Separate multiple directories in the command-line syntax with spaces.


Example 6–9 Displaying the Size of Directories, Subdirectories, and Files

The following example shows the 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 and includes the sizes of all the subdirectories and files that are contained within each directory. The total number of blocks that are contained in each directory is also displayed.


$ du /var/adm /var/spool/lp
2       /var/adm/exacct
2       /var/adm/log
2       /var/adm/streams
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
258     /var/adm
4       /var/spool/lp/admins
2       /var/spool/lp/requests/printing....
4       /var/spool/lp/requests
4       /var/spool/lp/system
2       /var/spool/lp/fifos
24      /var/spool/lp

The following example shows directory sizes in 1024–byte blocks.


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

ProcedureHow to Display the User Ownership of Local UFS File Systems

  1. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands. For more information about roles, see Configuring RBAC (Task Map) in System Administration Guide: Security Services.

  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 for that file system.


    Note –

    The quot command works only on local UFS file systems.



Example 6–10 Displaying the User Ownership of Local UFS File Systems

In the following example, users of the root (/) file system are displayed. In the subsequent example, 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 by using the ls or find commands. For more information, see the ls(1) and find(1) man pages.

Other ways to conserve disk space include emptying temporary directories such as the directories located in /var/tmp or /var/spool, and deleting core and crash dump files. For more information about crash dump files, refer to Chapter 17, Managing System Crash Information (Tasks).

ProcedureHow to List the Newest Files

  1. 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 that you want to search.


Example 6–11 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

ProcedureHow to Find and Remove Old or Inactive Files

  1. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands. For more information about roles, see Configuring RBAC (Task Map) in System Administration Guide: Security Services.

  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) that you specify.

    -mtime +nnn

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

    filename

    Identifies the file that contains the list of inactive files.

  3. Remove the inactive files found listed in the previous step.


    # rm `cat filename`
    

    where filename identifies the file that was created in the previous step. This file contains the list of inactive files.


Example 6–12 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`
#

ProcedureHow to Clear Out Temporary Directories

  1. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands. For more information about roles, see Configuring RBAC (Task Map) in System Administration Guide: Security Services.

  2. Change to the directory that you want to clean out.


    # cd directory
    

    Caution – Caution –

    Ensure that you are in the correct 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 that contain unnecessary, temporary or obsolete subdirectories and files.

  5. Delete these subdirectories and files by repeating Step 3.


Example 6–13 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
#

ProcedureHow to Find and Delete core Files

  1. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands. For more information about roles, see Configuring RBAC (Task Map) in System Administration Guide: Security Services.

  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 6–14 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 {} \;

ProcedureHow to Delete Crash Dump Files

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

  1. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands. For more information about roles, see Configuring RBAC (Task Map) in System Administration Guide: Security Services.

  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 –

    Ensure you are in the correct 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 were removed.


    # ls
    

Example 6–15 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