Skip to contentSkip to conversation

simple scripting question

DISCUSSION urgrue 3 participants 3 messages Jan 27, 2003 – Jan 28, 2003

lore
Share & tools
lore

urgrue

author
#0 lore raw

i have several dirs and i want to delete the ones that are older than 60 days.
currently im doing it like this:
find /path/backups-* -type d -mtime +60 | xargs rm -r

but i dont want to go through the CONTENTS of the dirs and delete every individual file that is older than 60d. i want to either delete or not delete the whole dir depending on its timestamp.

but i only know of find that accepts something as spiffy as -mtime +60, and i cant find any options for it like "--non-recursive".

any suggestions?
basically this is for removing outdated backups.

#1 lore raw
Quoted 11 lines · urgrue

i have several dirs and i want to delete the ones that are older than 60 days.
currently im doing it like this:
find /path/backups-* -type d -mtime +60 | xargs rm -r

but i dont want to go through the CONTENTS of the dirs and delete every individual file that is older than 60d. i want to either delete or not delete the whole dir depending on its timestamp.

but i only know of find that accepts something as spiffy as -mtime +60, and i cant find any options for it like "--non-recursive".

find <dirs> -type d -mindepth 1 -maxdepth 1

will find exactly those directories whose parent is one of <dirs>.

Signature · 1 line
Glynn Clements <[email protected]>
#2 lore raw
In reply to urgrue
Quoted 5 lines · urgrue

i have several dirs and i want to delete the ones that are older than 60 days.
currently im doing it like this:
find /path/backups-* -type d -mtime +60 | xargs rm -r

Quoted 7 lines

but i dont want to go through the CONTENTS of the dirs and delete every individual file that is older than 60d. i want to either delete or not delete the whole dir depending on its timestamp.

but i only know of find that accepts something as spiffy as -mtime +60, and i cant find any options for it like "--non-recursive".

Why cannot you use -maxdepth 0 option?

liana:~$ man find
[...]
       -maxdepth levels
              Descend  at  most  levels  (a  non-negative integer) levels of
              directories below the command line arguments.   `-maxdepth  0'
              means  only  apply  the  tests and actions to the command line
              arguments.
[...]

Mikhail