Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

At our university we have the policy that on certain disks' data is deleted if it is not modified for six months. Now I would like to list all files that have not been modified in the last five months.

How can I do this? I have access to all basic Linux tools, like Bash, find, etc.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

It is

find directory -mtime +150

for the files not modified in this period (-150 will list the modified files).

share|improve this answer
    
That will list files that have been modified more than 150 days ago. –  Juha Syrjälä Jul 20 '10 at 12:46
    
Yes... and they are the the same as the files not modified in the 150 last days (or 5 months) of course: this command lists all the files excepting the files modified in the last 5 months... so the others (listed) are the not modified in this time. –  laurent Jul 20 '10 at 20:19

If you need to be more precise regarding leap years and particular month lengths, you can do this:

find /dir/to/start/from -type f -mtime +$(((10#$(date +%s) - 10#$(date -d "now - 5 months" +"%s")) / (24*60*60)))

Here's how the number of days would vary if the above were run on the first day of each month in 2010:

1 153
2 153
3 151
4 151
5 150
6 150
7 149
8 152
9 153
10 153
11 153
12 153

As you can see "150" is only an approximation. However, for most purposes approximations (such as 24*60*60 as a matter of fact) are good enough.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.