Go to main content

Managing Devices in Oracle® Solaris 11.3

Exit Print View

Updated: April 2018
 
 

Managing Disk Use

Use the following task map for a list of management tasks you can perform on disks.

Table 11  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.
Show sizes and other information about files that are stored on the system disks.
Display information about the size of directories and subdirectories.
Display the size of one or more directories, subdirectories, and files by using the du command.
Perform disk maintenance.
Ensure disk availability by regularly removing unnecessary files and directories. Identify old files by listing them based on time stamps.
Find and remove old or inactive files.
Use the find to identify inactive files that can be marked for deletion.
Clear out temporary directories.
Locate temp directories, then use the rm –r * command to remove the entire directory.
Find and delete core files.
Find and delete core files by using the find . -name core -exec rm {} \; command.

The following list summarizes the commands available for displaying information about file size and disk space.

  • zpool list – displays pool space size, how much space is allocated to datasets and internal metadata and how much space is unallocated. See the zpool(1M) man page.

  • zfs list – displays amount of space consumed by datasets and any descendents, the amount of space available to the dataset and its descendents, and the amount of data that is referenced by this dataset, which may or may not be shared with other datasets in the pool. See the zfs(1M) man page.

  • df – reports the number of free disk blocks and files. See the df(1M) man page.

  • du – summarizes disk space allocated to each subdirectory. See the du(1) man page.

  • find –size – searches recursively through a directory based on the size specified with the –size option. See the find(1) man page.

  • ls – lists the size of a file in the power of 1024 scaling. See the ls(1) man page.

The zpool list and zfs list commands are better 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 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.

Use of Disk Space on ZFS File Systems

To display information about how ZFS disk space is used, use the zpool command as follows:

# 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 Gbyte allocated and 580 Gbyte free.

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

The command's –r option enables you 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  -

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

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.

Using the ls Command

The ls commands displays a list of files on 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 the files and directories and shows the sizes in blocks.

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

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

$ cd /var/adm
$ ls -lh
total 148
-rw-------   1 uucp     bin            0 Nov 26 09:25 aculog
-r--r--r--   1 root     other       342K Nov 26 13:56 lastlog
-rw-r--r--   1 root     root         20K Nov 26 13:55 messages
-rw-r--r--   1 root     bin         3.3K Nov 26 13:56 utmpx
-rw-r--r--   1 adm      adm          19K Nov 26 13:56 wtmpx

In the following example that uses the –sh options, the first column of the output indicates the blocks that are used by the files.

$ ls -sh
880 -r--r--r--   1 root     other       342K Nov 26 13:56 lastlog
 25 -rw-r--r--   1 root     root         20K Nov 26 13:55 messages
  7 -rw-r--r--   1 root     bin         3.3K Nov 26 13:56 utmpx
 24 -rw-r--r--   1 adm      adm          19K Nov 26 13:56 wtmpx

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 about the sort command, 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 use the following command syntax:

$ find directory -size +nnn

where directory specifies the directory that you want to search and nnn is a number that represents a size in 512-byte blocks which you specify for the –size option.

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

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

The du command displays the size of the directory you specify as well as all the subdirectories. You can use the command with the following options:

  • –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.

Use the following command syntax:

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

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 sizes of different directories, specify those directories in the command. The following example shows the comparison of sizes between /var/adm and /var/spool/lp.

$ 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