System Administration Guide: Advanced Administration

How to Find and Remove Old or Inactive Files

  1. Become superuser.

  2. 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

    Identifies the directory you want to search. Directories below this directory are also searched. 

    -atime +nnn

    Finds files that have not been accessed within the number of days (nnn) you specify. 

    -mtime +nnn

    Finds files that have not been modified within the number of days (nnn) you specify. 

    filename

    Identifies the file that contains the list of inactive files.

  3. Remove the inactive files that you listed in the previous step.


    # rm `cat filename`
    

    filename identifies the file created in the previous step which contains the list of inactive files.

Example—Finding and Removing Old or 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`
#