Skip to content

Question of the Day - 19 Sept. 2007

What command would you use in order to delete all core files that haven’t been touched in three or more days?

3 Comments

  1. Bruce

    Depends on what you mean by “touched”, but something like:
    find ~ -name core -type f ! -atime -3 -exec rm -f {} \;

    should work for everything from $HOME on down.

    Depending on your shell you may need to escape certain things.

    Posted on 21-Sep-07 at 6:12 pm | Permalink
  2. Yup, that’s an excellent solution. I would change the -name thusly:

    ‘(’ -name core -o name ‘core.[0-0]*’ ‘)’

    This picks up both ‘core’ files and core.nnnn files, which are often also generated by appending the PID (see /proc/sys/kernel/core_pattern and man core(5) for more). Also, -atime +3 checks for files that haven’t been accessed in 3 days.

    And yes, escaping the -exec command in find is a gnarly thing, something I can never keep straight!

    Posted on 23-Sep-07 at 9:02 am | Permalink
  3. Bruce

    Yeah, I considered that but “went literal” on the problem.

    One small nit (and we are talking really, really small) is that -atime +3 looks for *greater* than 3 days so to get an inclusion of *exactly* three days I inverted the whole thing. :)

    Posted on 24-Sep-07 at 3:11 pm | Permalink

Post a Comment

Your email is never published nor shared.