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).
Task |
Description |
For Instructions |
---|---|---|
Display information about files and disk space. |
Display information about how disk space is used by using the df command. | |
Display the size of files. |
Display information about the size of files by using the ls command with the -lh options. | |
Find large files. |
The ls -s command allows you to sort files by size, in descending order. | |
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. | |
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. | |
List the newest files. |
Display the most recently created or changed files first, by using the ls -t command | |
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. | |
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. | |
Delete crash dump files. |
Delete crash dump files that are located in the /var/crash/ directory by using the rm * command. |
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 | |
du |
Summarizes disk space allocated to each subdirectory | |
find -size |
Searches recursively through a directory based on the size specified with the -size option | |
ls -lh |
Lists the size of a file in the power of 1024 scaling |
Display information about how disk space is used by using the df command.
$ df [directory] [-h] [-t] |
With no options, lists all mounted file systems and their device names, the number of 512-byte blocks used, and the number of files.
Specifies the directory whose file system you want to check.
Displays disk space in the power of 1024 scaling.
Displays the total blocks as well as the 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 ): 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 |
In the following example, file system information 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.
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 |
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.
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 Solaris daemon processes and utilities.
Change to the directory where the files you want to check are located.
Display the size of the files.
$ ls [-lh] [-s] |
Displays a list of files and directories in long format, showing the sizes in bytes. (See the example that follows.)
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.
Displays a list of the files and directories, showing the sizes in blocks.
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 |
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.
$ 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 |
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 |
To locate and display the names of files that exceed a specified size, use the find command.
$ find directory -size +nnn |
Identifies the directory that you want to search.
Is a number of 512-byte blocks. Files that exceed this size are listed.
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 |
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.
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 ...] |
Displays the size of each directory that you specify, including each subdirectory beneath it.
Displays the size of each file and subdirectory, and the total number of blocks that are contained in the specified directory.
Displays the total number of blocks that are contained in the specified directory.
Displays the size of each directory in 1024–byte blocks.
Displays the size of each directory in 1000–byte blocks.
Identifies one or more directories that you want to check. Separate multiple directories in the command-line syntax with spaces.
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.Eng.Sun.COM 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 |
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.
Display users, directories, or file systems, and the number of 1024-byte blocks used.
# quot [-a] [filesystem ...] |
Lists all users of each mounted UFS file system and the number of 1024-byte blocks used.
Identifies a UFS file system. Users and the number of blocks used are displayed for that file system.
The quot command works only on 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 |
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).
List files, displaying the most recently created or changed files first, by using the ls -t command.
$ ls -t [directory] |
Sorts files by latest time stamp first.
Identifies the directory that you want to search.
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 |
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.
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 & |
Identifies the directory you want to search. Directories below this directory are also searched.
Finds files that have not been accessed within the number of days (nnn) that you specify.
Finds files that have not been modified within the number of days (nnn) that you specify.
Identifies the file that contains the list of inactive files.
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.
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` # |
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.
Change to the directory that you want to clean out.
# cd directory |
Ensure that you are in the correct directory before completing Step 3. Step 3 deletes all files in the current directory.
Delete the files and subdirectories in the current directory.
# rm -r * |
Change to other directories that contain unnecessary, temporary or obsolete subdirectories and files. Delete these subdirectories and files by repeating Step 3.
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 # |
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.
Change to the directory where you want to search for core files.
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 jones user account by using the find command.
# cd /home/jones # find . -name core -exec rm {} \; |
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.
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.
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.
Ensure you are in the correct directory before completing Step 3. Step 3 deletes all files in the current directory.
Remove the crash dump files.
# rm * |
Verify that the crash dump files were 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 |