Contained Within
Find More Documentation
Featured Support Resources
| PDF로 이 문서 다운로드
Managing Disk Use
65
- 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.
-
Displaying Blocks and Files Used
- Use the df command and its options to report the number of free disk blocks and files. For more information, see the df(1M) man page.
· How to Display Information About Blocks, Files, and Disk Space
- Display information about how disk space is used by using the df command.
-
$ df [directory] [-F fstype] [-g] [-k] [-t]
|
- In this command,
-
| 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 | Is a 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. |
-
Note - For remotely mounted file systems, "-1 files" is displayed instead of the number of files.
Examples--Displaying Information About Blocks, Files, and Disk Space
- In the following example, the file systems root (/), /usr, /proc, and /tmp are on the local disk. The other file systems are mounted by NFS and do not use local disk resources.
-
$ df
/ (/dev/dsk/c0t0d0s0): 21338 blocks 9592 files
/usr (/dev/dsk/c0t0d0s6): 46722 blocks 34103 files
/proc (/proc ): 0 blocks 112 files
/tmp (swap ): 66696 blocks 3177 files
/root (saturn:(pid132)): 0 blocks -1 files
/home (saturn:(pid132)): 0 blocks -1 files
/src (saturn:(pid132)): 0 blocks -1 files
/nse (saturn:(pid132)): 0 blocks -1 files
/net (saturn:(pid132)): 0 blocks -1 files
|
- 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 22199 11530 8459 58% /
/dev/dsk/c0t0d0s6 73399 50038 16031 76% /usr
/proc 0 0 0 0% /proc
swap 33364 8 33356 0% /tmp
saturn:(pid132) 0 0 0 0% /root
saturn:(pid132) 0 0 0 0% /home
saturn:(pid132) 0 0 0 0% /src
saturn:(pid132) 0 0 0 0% /nse
saturn:(pid132) 0 0 0 0% /net
|
- The following example shows information about the same system as the previous example, but only UFS file system information is displayed. Although /proc and /tmp are local file systems, they are not UFS file systems (/proc is a PROCFS file system, and /tmp is a TMPFS file system).
-
$ df -F ufs
/ (/dev/dsk/c0t0d0s0): 21338 blocks 9592 files
/usr (/dev/dsk/c0t0d0s6): 46722 blocks 34103 files
|
- 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): 21338 blocks 9592 files
total: 44398 blocks 11264 files
/usr (/dev/dsk/c0t0d0s6): 46722 blocks 34103
files
total: 146798 blocks 37888 files
/proc (/proc ): 0 blocks 112 files
total: 0 blocks 140 files
/tmp (swap ): 66712 blocks 3177 files
total: 66728 blocks 3179 files
/root (saturn:(pid132)): 0 blocks -1 files
total: 0 blocks -1 files
/home (saturn:(pid132)): 0 blocks -1 files
total: 0 blocks -1 files
/src (saturn:(pid132)): 0 blocks -1 files
total: 0 blocks -1 files
/nse (saturn:(pid132)): 0 blocks -1 files
total: 0 blocks -1 files
/net (saturn:(pid132)): 0 blocks -1 files
total: 0 blocks -1 files
|
Checking the Size of Files
- You can check the size of files and sort them by using the ls command, and 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.
· How to Display the Size of Files
-
-
Change the directory to where the files you want to check are located.
-
Display the size of the files.
-
- In this command,
-
| -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. |
Examples--Displaying the Size of Files
- The following example shows that lastlog, wtmp, and wtmpx are substantially larger than the other files in the /var/adm directory.
-
venus% cd /var/adm
venus% ls -l
total 434
-r--r--r-- 1 root other 585872 Jan 28 14:53 lastlog
drwxrwxr-x 2 adm adm 512 Dec 1 16:35 log
-rw-r--r-- 1 root other 408 Jan 28 14:15 messages
-rw-r--r-- 1 root other 177 Jan 24 16:56 messages.0
-rw-r--r-- 1 root other 177 Jan 17 16:13 messages.1
-rw-r--r-- 1 root other 0 Jan 4 04:05 messages.2
-rw-r--r-- 1 root other 562 Jan 2 13:13 messages.3
drwxrwxr-x 2 adm adm 512 Dec 1 16:35 passwd
drwxrwxr-x 2 adm sys 512 Jan 28 11:38 sa
-rw-rw-rw- 1 bin bin 0 Nov 26 10:56 spellhist
-rw------- 1 root root 1319 Jan 28 14:58 sulog
-rw-r--r-- 1 root bin 288 Jan 28 14:53 utmp
-rw-r--r-- 1 root bin 2976 Jan 28 14:53 utmpx
-rw-rw-r-- 1 adm adm 12168 Jan 28 14:53 wtmp
-rw-rw-r-- 1 adm adm 125736 Jan 28 14:53 wtmpx
|
- The following example shows that lpNet uses eight blocks and lpsched and lpsched-1 use two blocks each.
-
venus% cd /var/lp/logs
venus% ls -s
total 14 2 lpsched-1 0 lpsched-4 0 requests-2
8 lpNet 2 lpsched-2 0 requests
2 lpsched 0 lpsched-3 0 requests-1
venus%
|
· How to Find Large Files
-
-
Change directory to where you want to search.
-
Display the size of files in blocks from largest to smallest.
-
$ ls -s | sort -nr | more
|
- In this command,
-
sort -nr......Sorts the list of files by block size from smallest to largest.
Example--Finding Large Files
- In the following example, wtmpx and lastlog are the largest files in the /var/adm directory.
-
$ cd /var/adm
$ ls -s | sort -nr | more
total 624
320 wtmpx
128 lastlog
74 pacct
56 messages
30 wtmp
6 utmpx
2 utmp
2 sulog
2 sa
2 passwd
2 log
0 spellhist
|
· How to Find Files That Exceed a Given Size Limit
- To locate and display the names of files that exceed a specified size, use the find command.
-
$ find directory -size +nnn
|
- In this command,
-
| directory | Is the directory you want to search. |
| +nnn | Is a number of 512-byte blocks. Files that exceed this size are listed. |
Example--Finding Files That Exceed a Given Size Limit
- 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
|
Checking the Size of Directories
- 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 the du(1M)and quot(1M) man pages.
· How to Display the Size of Directories, Subdirectories, and Files
- 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 ...]
|
- In this command,
-
| 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. |
Examples--Displaying the Size of Directories, Subdirectories, and Files
- The following example displays the sizes of two directories and all the subdirectories they contain.
-
$ du /var/log /var/cron
4 /var/log
3250 /var/cron
|
- 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 -a /var/log /var/cron
0 /var/log/authlog
0 /var/log/syslog
2 /var/log/sysidconfig.log
4 /var/log
3248 /var/cron/log
3250 /var/cron
|
- The following example displays the total sizes of two directories.
-
$ du -s /var/log /var/cron
4 /var/log
3250 /var/cron
|
· How to Display the User Allocation of Local UFS File System
-
-
Become root.
-
Display users, directories, or file systems, and the number of 1024-byte blocks used.
-
- In this command,
-
| -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. |
-
Note - The quot command works only on local UFS file systems.
Example--Displaying the User Allocation of 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:
35400 bin
14312 smtp
183 adm
49 lp
47 uucp
37 bob
28 sys
2 mary
# quot -a
/dev/rdsk/c0t0d0s0 (/):
35400 bin
14312 smtp
183 adm
49 lp
47 uucp
37 bob
28 sys
2 mary
/dev/rdsk/c0t0d0s6 (/usr):
104276 smtp
56567 bin
2000 lp
698 uucp
1 adm
/dev/rdsk/c0t0d0s7 (/export/home):
617 smtp
|
Finding and Removing Old and 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 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 ones located in /var/tmp or /var/spool, and deleting core and crash dump files. For more information about these files, refer to "Crash Dump Files" and "Message Files" on page 1244.
· How to List the Newest Files
- List files, displaying the most recently created or changed files first, by using the ls -t command.
-
- In this command,
-
directory........Is the directory you want to search.
Verification--Listing the Newest Files
- Verify that the first files displayed by ls -t are the files that have been created or changed most recently by using ls -l to list the date and time for all files in a directory.
Example--Listing the Newest Files
- The following example shows how to use ls -t to locate the most recent files within the /var/adm directory. sulog, messages, utmpx, wtmpx, utmp, and lastlog were created or edited most recently. This is verified using output from ls -l, which shows that these three files were created or edited in March, while the other files in /var/spool were created or edited earlier.
-
$ ls -t /var/adm
sulog wtmpx wtmp messages.1 vold.log spellhist
messages utmp sa messages.2 log aculog
utmpx lastlog messages.0 messages.3 acct passwd
$ ls -l /var/spool
total 686
drwxr-xr-x 5 adm adm 512 Feb 13 16:20 acct
-rw------- 1 uucp bin 0 Feb 13 16:04 aculog
-r--r--r-- 1 root other 8456 Mar 27 10:34 lastlog
drwxr-xr-x 2 adm adm 512 Feb 13 16:36 log
-rw-r--r-- 1 root other 117376 Mar 27 13:11 messages
-rw-r--r-- 1 root other 4620 Jan 30 08:30 messages.0
-rw-r--r-- 1 root other 11176 Jan 23 04:30 messages.1
-rw-r--r-- 1 root other 60 Jan 13 09:45 messages.2
-rw-r--r-- 1 root other 0 Jan 31 04:05 messages.3
drwxr-xr-x 2 adm adm 512 Feb 13 16:03 passwd
drwxr-xr-x 2 adm sys 512 Mar 20 06:59 sa
-rw-rw-rw- 1 bin bin 0 Feb 13 16:04 spellhist
-rw------- 1 root root 1647 Mar 27 13:28 sulog
-rw-r--r-- 1 root bin 504 Mar 27 10:34 utmp
-rw-r--r-- 1 root bin 5208 Mar 27 10:34 utmpx
-rw-rw-rw- 1 root root 500 Jan 11 14:40 vold.log
-rw-rw-r-- 1 adm adm 14724 Mar 27 10:34 wtmp
-rw-rw-r-- 1 adm adm 151404 Mar 27 10:34 wtmpx
|
· How to Find and Remove Old or Inactive Files
-
-
Become root.
-
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
|
- In this command,
-
| directory | Is the 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 | Is the file containing the list of inactive files. |
-
-
Remove the inactive files that you listed in the previous step.
-
- In this command,
-
filename.......Is the file containing the list of inactive files.
Example--Finding and Removing Old or 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.
-
# 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/wtmp
/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`
|
· How to Clear Out Temporary Directories
-
-
Become root.
-
Change to the /var/tmp directory.
-
-
Caution - 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.
-
-
-
Change to other directories containing temporary or obsolete subdirectories and files (for example, mail, lost+found, or quotas), and delete them by repeating Step 3 above.
Verification--Clearing Out Temporary Directories
- To verify that you have removed all files from a temporary directory, use the ls command within that directory.
Example--Clearing Out Temporary Directories
- 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
#
|
· How to Find and Delete core Files
-
-
Become root.
-
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 {} \;
|
Example--Finding and Deleting core Files
- 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 {} \;
|
· How to Delete Crash Dump Files
- 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.
-
-
Become root.
-
Change to the directory where crash dump files are stored.
-
- In this command,
-
system........Is the system that created the crash dump files.
-
Caution - 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.
-
Verification--Deleting Crash Dump Files
- To verify that you have removed crash dump files from their directory, use the ls command.
Example--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
#
|
|
|