Re: Delete all subdirectories (recursively), except a few
"'Nick Anderson' via help-cfengine" <[email protected]> Tue, 30 Apr 2024 17:48:37 -0500
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <CAE46pPvKtymELL+PAQTz+oeE-BBmvQH6PV=n+eNPgAV2GN=MCA@mail.gmail.com> |
I'd probably consider using find() files to enumerate, possibly filter that list further and then iterate over that list to delete. On Tue, Apr 30, 2024, 4:46 PM Bob <[email protected]> wrote: > I have to manage a directory that many people can create subdirectories > and files. > > Let's say the directory is "/srv/data". I would like to remove any other > directories created (recursively) that are older than 7 days and not is a > predefined list. I can't quite get there. > > bundle agent main > { > vars: > linux:: > "keep_dirs" slist => { "project1", "project2", "etc" }; > > files: > linux: > "/srv/data" > delete => tidy, > file_select => exclude_name_age_dir("@(keep_dirs)", "7"); > depth_search => recurse("inf"); > } > body file_select exclude_name_age_dir(name,days) > { > leaf_name => { "$(name)" }; > mtime => irange(0,ago(0,0,"$(days)",0,0,0)); > file_types => { "dir" }; > file_result => "file_types.mtime.!leaf_name"; > } > > This will delete any folders that are empty, but doesn't quite do what I > need. > > I appreciate any suggestions. > > > -- > You received this message because you are subscribed to the Google Groups > "help-cfengine" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/help-cfengine/2991fbc6-a151-43ea-aa27-a0d8f20a38fdn%40googlegroups.com > <https://groups.google.com/d/msgid/help-cfengine/2991fbc6-a151-43ea-aa27-a0d8f20a38fdn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "help-cfengine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/CAE46pPvKtymELL%2BPAQTz%2BoeE-BBmvQH6PV%3Dn%2BeNPgAV2GN%3DMCA%40mail.gmail.com.