compare files in the system with last modified date

HI,

I have some files in my Linux machine that are very old and occupy a HUGe amount of space. I am trying to delete these files from the system so that it will be easy for me to add some files. I would like to know if this can done through a Perl or a shell script.

What i want to do is i want to compare the files with the current date stamp and list all the files that are were untouched for more than TWO years.

Please can some whe help me on how this can be done.

I am new to Linux and need Guidance on this.

Thanks,
Sandeep

man test

     file1 -nt file2
                   True if file1 exists and is newer than file2.

     file1 -ot file2
                   True if file1 exists and is older than file2.

So if you have a file with your cutoff timestamp you can compare others such:

if test $candidate-file -ot $cutoff-file
then
     echo $candidate-file
fi

Hi Porter,

The script you have given is probably if i know the filename, but in my case i don't know the names of all the files( thats were the problem lies)....I need to find files that have not been changed from past two years by compariing them with respect to the last modified date. Also i am starter to shell scripting so please help me with the complete code. I really appreciate you time to look into this thread.Thanks so much.

Please let me know your thoughts.

Thanks,
Sandeep

try

find directory ! -newer candidate | xargs ls -ld

when that is showing you the correct files

replace "ls -ld" with "rm"

Note, it is your responsiblity to have the appropriate backups. Do not attempt this if you don't know what you are doing.

HI porter,

I am bit confused with your inputs. can you just leme know how this can be written in a shell script.

THanks for your time

Sandeep

#!/bin/sh
find directory ! -newer cutoff-file | xargs ls -ld

where directory is the path to the directory you want to clean
cutoff-file is the path to a file which has the filestamp you want to compare with.

:b:confirm:b: