How to Find and Remove Old or Inactive Files

  1. Become an administrator.
  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) that you specify.
    -mtime +nnn
    Finds files that have not been modified within the number of days (nnn) that you specify.
    filename
    Identifies the file that contains the list of inactive files.
  3. 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.

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`
#

 

Another ways to remove

find /path/to/files -mtime +60 -print

Then the version with -exec rm -v {} \; to remove the files (when you are ready).


Leave a Reply

Your email address will not be published. Required fields are marked *

20 − 13 =

Related Posts

Oracle

How to Collect a Snapshot on SPARC M series servers Mx000 and M10-x systems

Running snapshot The syntax varies slightly from the Mx000 to the M10-x .The M10 requires a “-a” option to collect logs from all chassis. The two most common usages are described below. The first example Read more…

Oracle

Verifying HBA card connectivity in Solaris

1. Use the “luxadm -e port” command to verify HBA has established communication with a node. # luxadm -e port /devices/[email protected]/[email protected]/[email protected]/[email protected]/SUNW,[email protected]/[email protected],0:devctl CONNECTED /devices/[email protected]/[email protected]/[email protected]/[email protected]/SUNW,[email protected],1/[email protected],0:devctl CONNECTED CONNECTED : HBA has established connection with either target or initiator. Read more…

Oracle

Setting Network IPMP & Aggregate Solaris 11

Configure an Active-Standby IPMP Group 1. Create an IPMP interface ipadm create-ip net0 ipadm create-ip net1 ipadm create-ipmp ipmp0 2. Add the physical interfaces net0 and net1 to the ipmp group. ipadm add-ipmp -i net0 Read more…