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.
"How to Display Information About Blocks, Files, and Disk Space"
"How to Display the Size of Directories, Subdirectories, and Files"
"How to Display the User Allocation of Local UFS File Systems"
Use the df command and its options to report the number of free disk blocks and files. For more information, see df(1M).
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. |
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, 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/c0t0d0s0 192807 49042 124485 29% / /dev/dsk/c0t0d0s6 1190551 680444 450580 61% /usr /proc 0 0 0 0% /proc fd 0 0 0 0% /dev/fd mnttab 0 0 0 0% /etc/mnttab swap 198056 0 198056 0% /var/run swap 198064 8 198056 1% /tmp /dev/dsk/c0t0d0s5 192807 2031 171496 2% /opt /dev/dsk/c0t0d0s7 217191 9 195463 1% /export/home venus:/usr/dist 20612581 13237326 6963005 66% /usr/dist |
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/c0t0d0s0 ): 287530 blocks 92028 files /usr (/dev/dsk/c0t0d0s6 ): 1020214 blocks 268550 files /opt (/dev/dsk/c0t0d0s5 ): 381552 blocks 96649 files /export/home (/dev/dsk/c0t0d0s7 ): 434364 blocks 108220 files |
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 |
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).
Change the directory to where the files you want to check are located.
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. |
The following example shows that lastlog and messages are larger than the other files in the /var/adm directory.
$ cd /var/adm $ ls -l total 144 drwxrwxr-x 5 adm adm 512 Sep 1 14:11 acct/ -rw------- 1 uucp bin 0 Sep 1 14:08 aculog -r--r--r-- 1 root root 350700 Sep 3 10:37 lastlog drwxr-xr-x 2 adm adm 512 Sep 1 14:08 log/ -rw-r--r-- 1 root root 14619 Sep 2 16:11 messages -rw-r--r-- 1 adm adm 8200 Sep 3 14:35 pacct -rw-r--r-- 1 adm adm 920 Sep 3 10:47 pacct1 drwxr-xr-x 2 adm adm 512 Sep 1 14:08 passwd/ drwxrwxr-x 2 adm sys 512 Sep 1 14:11 sa/ drwxr-xr-x 2 root sys 512 Sep 1 14:36 sm.bin/ -rw-rw-rw- 1 root bin 0 Sep 1 14:08 spellhist -rw------- 1 root root 420 Sep 3 14:17 sulog -rw-r--r-- 1 root bin 4092 Sep 3 10:37 utmpx -rw-r--r-- 1 root root 122 Sep 1 15:39 vold.log -rw-r--r-- 1 adm adm 11904 Sep 3 10:47 wtmpx |
The following example shows that lpsched.1 uses two blocks.
$ cd /var/lp/logs $ ls -s total 2 0 lpsched 2 lpsched.1 |
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. |
In the following example, lastlog and messages 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 |
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. |
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 |
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).
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. |
The following example displays the total sizes of two directories and all the subdirectories they contain.
$ du -s /var/adm /var/spool/lp 130 /var/adm 40 /var/spool/lp |
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 /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 |
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. |
The quot command works only on 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 |
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 39, Managing System Crash Information.
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. |
The following example shows how to use ls -tl to locate the most recent 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 |
Become superuser.
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 |
Remove the inactive files that you listed in the previous step.
# rm `cat filename` |
filename |
File created in previous step which contains the list of 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/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` # |
Change to the /var/tmp directory.
# cd /var/tmp |
Be sure you are in the right directory before completing the following step. The next step deletes all files in the current directory.
Delete the files and subdirectories in the current directory.
# rm -r * |
Change to other directories containing unnecessary temporary or obsolete subdirectories and files, and delete them by repeating Step 3 above.
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 # |
Change the directory to where you want to start the search.
Find and remove any core files in this directory and its subdirectories.
# find . -name core -exec rm {} \; |
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 {} \; |
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.
Change to the directory where crash dump files are stored.
# cd /var/crash/system |
system |
System that created the crash dump files. |
Be sure you are in the right directory before completing the following step. The next step deletes all files in the current directory.
Remove the crash dump files.
# rm * |
Verify the crash dump files are removed.
# ls |
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 |