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 69, Generating and Saving 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 -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/adm 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 |
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 by this command 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/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` |
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 temporary or obsolete subdirectories and files (for example, mail, lost+found, or quotas), 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 * # |