Go to main content

Managing Devices in Oracle® Solaris 11.4

Exit Print View

Updated: November 2020
 
 

Managing Disk Use

This chapter describes how to manage disk use. The following task map points to the management tasks you can perform on disks.

Table 5  Managing Disk Use Task Map
Task
Description
For Instructions
Display information about the use of disk space on the system.
Show how disk space is currently being used.
Display information about sizes of files that use up disk space.
Shows sizes and other information about files that are stored on the system disks.
Display information about the size of directories and subdirectories.
Displays the size of one or more directories, subdirectories, and files by using the du command.
Perform disk maintenance.
Ensure sdisk availability by regularly removing unnecessary files and directories. Identifies old files by listing them based on time stamps.
Find and remove old or inactive files.
Uses the find to identify inactive files that can be marked for deletion.
Clear out temporary directories.
Locates temp directories, then uses the rm –r * command to remove the entire directory.
Find and delete core files.
Finds and deletes core files by using the find . -name core -exec rm {} \; command.

Displaying Information About Disk Space

The command you use to obtain information about the use of disk space on your system depends on the file system. The following sections show how to use the appropriate command for the file system to display data about disk use.

Displaying the Use of Disk Space on ZFS File Systems

To display information about how ZFS disk space is used, use the zpool command.

# zpool list root-pool

where root-pool is the name of the root pool on the system. The following example provides information about rpool, which has 10.0 Gbytes allocated and 580 Gbytes free.

# zpool list rpool
NAME   SIZE  ALLOC   FREE  CAP  HEALTH  ALTROOT
rpool   68G  10.0G  58.0G  14%  ONLINE  -

Use the –r option to compare available space with actually used space in the root pool.

# zfs list -r rpool
NAME                        USED  AVAIL  REFER  MOUNTPOINT
rpool                      10.2G  56.8G   106K  /rpool
rpool/ROOT                 5.04G  56.8G    31K  legacy
rpool/ROOT/solaris         5.04G  56.8G  5.04G  /
rpool/dump                 1.00G  56.8G  1.00G  -
rpool/export                 63K  56.8G    32K  /export
rpool/export/home            31K  56.8G    31K  /export/home
rpool/swap                 4.13G  56.9G  4.00G  -

The zpool list and zfs list commands provide more targeted information than the legacy df and du commands for determining your available ZFS storage pool and file system space. With the legacy commands, you cannot easily discern between pool and file system space, nor do the legacy commands account for space that is consumed by descendent file systems or snapshots.

Displaying the Use of Disk Space on UFS File Systems

To display information about how UFS disk space is used, use the df command.

$ 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

To find out how disk space is used per user, use the quot command.

# quot /ufsfs
/dev/rdsk/c3t3d0s0:
21048   root
350   amy
250   rory

Note -  The quot command works only on local legacy UFS file systems.

Displaying Information About File Sizes

To check the size of files and sort them, use the ls command. To find files that exceed a size limit, use the find command. For more information, see the ls(1) and find(1) man pages.

Using the ls Command

The ls commands displays a list of files in a specific directory. The following ls options are useful for obtaining information about file sizes on the system:

  • –l – Displays a list of files and directories in long format and shows the sizes in bytes.

  • –h – Scales file sizes and directory sizes into KB, MB, GB, or TB when the file or directory size is larger than 1024 bytes.

  • –s – Displays a list of files and directories and shows the sizes in blocks.

For more information, see thels(1) man page.

The following example shows that the acct and sulog files are the two largest files in the /var/adm directory.

$ cd /var/adm
$ ls -lh
total 78
-rw-------   1 root     root         36K Nov 26 15:45 acct
-rw-------   1 uucp     bin            0 Nov 26 09:25 aculog
-rw-r--r--   1 root     root         20K Nov 26 13:55 messages
-rw-------   1 root     root         22K Nov 26 10:30 sulog

The following example uses the –sh option to indicate the blocks that are used by the files in the first column of the output.

$ ls -sh
 25 -rw-r--r--   1 root     root         20K Nov 26 13:55 messages
  7 -rw-------   1 root     root         36K Nov 26 15:45 acct
 24 -rw-------   1 root     root         22K Nov 26 10:30 sulog

You can combine the ls command with the sort command to display a directory's files in an ascending or descending order according to a criterion such as file size. For more information, see the sort(1) man page.

Using the find Command

The find command enables you to search for files that fit a specific search criteria. For example, to find files that exceed a specific file size, you would use the following command syntax:

$ find directory -size +nnn

where directory specifies the directory that you want to search and –size + nnn provides the desired size in 512-byte blocks.

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

Displaying Information About Directory Sizes

To display the size of directories and subdirectories, use the du command and options. Additionally, you can display the amount of disk space used by user accounts on local UFS file systems by using the quot command. For more information, see the du(1) and quot(8) man pages.

The du command has the following syntax:

$ du [options] [directory1 directory2 ...]

The du command options are:

  • –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 1000-byte blocks.

The following example shows the size of /var/adm and its subdirectories.

$ du /var/adm
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

To compare the sizes of different directories, specify those directories in the command. The following example compares the sizes of the /var/adm and /var/spool/lp directories.

$ du /var/adm /var/spool/lp
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