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 |