Delete program core file in bash script

1k Views Asked by At

I'm trying to delete the core file generated from when my program suddenly crashes.

For that i use this piece of code:

find . -name 'core' -delete

My question is: Is this a correct way of doing it ? Is there a better and more efficient way?

2

There are 2 best solutions below

4
On BEST ANSWER

If you indeed want to delete those core file, you can use:

find . -name "core*" -exec rm -f {} \;

Note: [including semicolon]

0
On

Indeed, it is hard (if not impossible at all) to come up with a "perfect solution" since the names are core files are customizable.

In linux, /proc/sys/kernel/core_pattern determines the name of core files. Therefore, you should check that to decide the pattern to be used in your "find" command.