Finding old directories with find -mtime

Finding old directories with find -mtime

Post by John McDonne » Fri, 08 Jun 2001 20:56:53



Hi all,

No flames please. This is not as easy as it looks...

The goal: The find all directories which are say over 30 days old and
print them...with a view to alerting users and possibly archiving
them... easy you say....

find . -type d -mtime +30 -prune -exec du -sk {} \\;|sort -nr |

This even nicely gives the size... but it doesn't do exactly what I
want, because there could be sub-dirs that might be very active. If I
leave out the prune I get lots more dirs, but I still don't know if
any one is really valid. I could add a depth option but that doesn't
help because it will still print out invalid dirs, just in a different
order...

The only solutions I see are.... find all dirs younger than 30 and
compare with the older ones and do lots of manipulating...or  make
some kind of recusive script to run under -exec in the find command.
Neither very elegant...

Example:
              |-->2 (35 days)-->6 (2 days)
1(100days)--->|-->3 (15 days)-->5 (35 days)
              |-->4 (40 days)    

what should be returned is
/1/4
/1/3/5
and nothing else... but find as outlined will get
/1
/1/2
/1/3/5
/1/4

This should be something lots of people would want to do. Am I missing
someting obvious?

John McDonnell.
Cork, Ireland.

 
 
 

Finding old directories with find -mtime

Post by Chris F.A. Johnso » Sat, 09 Jun 2001 06:30:48



Quote:> Hi all,

> No flames please. This is not as easy as it looks...

> The goal: The find all directories which are say over 30 days old and
> print them...with a view to alerting users and possibly archiving
> them... easy you say....

> find . -type d -mtime +30 -prune -exec du -sk {} \\;|sort -nr |

> This even nicely gives the size... but it doesn't do exactly what I
> want, because there could be sub-dirs that might be very active. If I
> leave out the prune I get lots more dirs, but I still don't know if
> any one is really valid. I could add a depth option but that doesn't
> help because it will still print out invalid dirs, just in a different
> order...

> The only solutions I see are.... find all dirs younger than 30 and
> compare with the older ones and do lots of manipulating...or  make
> some kind of recusive script to run under -exec in the find command.
> Neither very elegant...

For each directory that is older than 30 days, check to see whether there
are any active directories buried within it.

## untested
age=30
find . -type d -mtime +$age | while read dir
do
        if find $dir -type d ! -mtime +$age > /dev/null
        then
                echo "$dir has active directories"
        else
                echo "No active directories in $dir"
                ## do your  thing here
        fi
done

- Show quoted text -

Quote:

> Example:
>               |-->2 (35 days)-->6 (2 days)
> 1(100days)--->|-->3 (15 days)-->5 (35 days)
>               |-->4 (40 days)

> what should be returned is
> /1/4
> /1/3/5
> and nothing else... but find as outlined will get
> /1
> /1/2
> /1/3/5
> /1/4

> This should be something lots of people would want to do. Am I missing
> someting obvious?

> John McDonnell.
> Cork, Ireland.

--

        =================================================================



 
 
 

Finding old directories with find -mtime

Post by Heiner Marx » Sat, 09 Jun 2001 07:29:54




>Hi all,

>No flames please. This is not as easy as it looks...

>The goal: The find all directories which are say over 30 days old and
>print them...with a view to alerting users and possibly archiving
>them... easy you say....

>find . -type d -mtime +30 -prune -exec du -sk {} \\;|sort -nr |

>This even nicely gives the size... but it doesn't do exactly what I
>want, because there could be sub-dirs that might be very active. If I
>leave out the prune I get lots more dirs, but I still don't know if
>any one is really valid. I could add a depth option but that doesn't
>help because it will still print out invalid dirs, just in a different
>order...

>The only solutions I see are.... find all dirs younger than 30 and
>compare with the older ones and do lots of manipulating...or  make
>some kind of recusive script to run under -exec in the find command.
>Neither very elegant...

>Example:
>              |-->2 (35 days)-->6 (2 days)
>1(100days)--->|-->3 (15 days)-->5 (35 days)
>              |-->4 (40 days)    

>what should be returned is
>/1/4
>/1/3/5
>and nothing else... but find as outlined will get
>/1
>/1/2
>/1/3/5
>/1/4

>This should be something lots of people would want to do. Am I missing
>someting obvious?

I would proceed that way:
(1) create a list of candidates
(2) create a list of non-candidates
(3) derive implications from (2): collect all father directories
    of the non-candidates
(4) subtract (3) from (1)

(1)
    find . -type d -mtime +30 -print | sort > cands

(2)
    find . -type d -mtime -30 -print > noncands
    # maybe you will not want to restrict this to -type d !

(3)
    # the awk below should be a new awk (most are today)
    awk '
    {
        print
        n = split($0, a, "[/]")
        i = 1
        d = a[i++]
        if( d == "" ) d = "/" a[i++]
        while( i < n ) {
            print d
            d = d "/" a[i++]
        }
    }
    ' < noncands | sort -u > allnoncands

(4)
    comm -23 cands allnoncands > result

HTH.  HAND.
--

 
 
 

1. find isnt finding old articles?

I still have articles in /usr/spool/news/* that are older then 35 days :(
and the space is fuilling up did I enter the info wrong somehow? this is
running from userid news's crontab...

the more specific ones do seem to be working which is puzzleing me?

10 23 * * * find /usr/spool/news -type f -mtime +35 -print -exec rm {} \;
| Mail -s "Expire all news" usenet

this one doesnt work (it is really all on  1 line)

10 23 * * * find /usr/spool/news/alt/support/depression -type f -mtime
+15 -print -exec rm {} \; | Mail -s "Expire alt.support.depression" usenet

this one works fine  ?? (also all on 1 line)

there are articles that are more then 35 days old....
we get/post news thru suck/blow package, with Ed Carp's enhancements.

what can I do to

  (a) run 1 time (so its cleans up before the filesystem runs out of space)
  (b) get it run daily to contine housecleaning

thanks in advance

                                 a very *fuzzy*,
                                 fuzzy

2. How to turn off the special meaning of '\n' in comparison?

3. find -> cp with target in each found directory?

4. intallation error when loading data into ramdisk

5. "find"ing directories older than 7 days old.

6. Get IP address of connected socket?

7. Need to find vi command to remove ^H from command man find > find.txt

8. Speed of Linux

9. find without the "find: cannot read dir /usr/lost+found: Permission denied"

10. find, find, find

11. find -mtime on symbolic link?

12. find -name a* -mtime +1 -exec rm {} -- in hours not days --

13. find -name abc -mtime +1 -exec rm {} -- in hours not days --