Finding core dump files
Someone on the SVLUG list posted about a shell script he'd written to find core dumps.
It sounded like a simple task -- just
locate core | grep -w core
, right?
I mean, any sensible packager avoids naming files or directories
"core" for just that reason, don't they?
But not so: turns out in the modern world, insane numbers of software
projects include directories called "core", including projects that
are developed primarily on Linux so you'd think they would avoid it ...
even the kernel.
On my system, locate core | grep -w core | wc -l
returned 13641 filenames.
Okay, so clearly that isn't working. I had to agree with the SVLUG poster that using "file" to find out which files were actual core dumps is now the only reliable way to do it. The output looks like this:
$ file core
core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), too many program headers (375)
The poster was using a shell script, but I was fairly sure it could be done in a single shell pipeline. Let's see: you need to run locate to find any files with 'core" in the name.
Then you pipe it through grep to make sure the filename is actually core: since locate gives you a full pathname, like /lib/modules/3.14-2-686-pae/kernel/drivers/edac/edac_core.ko or /lib/modules/3.14-2-686-pae/kernel/drivers/memstick/core, you want lines where only the final component is core -- so core has a slash before it and an end-of-line (in grep that's denoted by a dollar sign, $) after it. So grep '/core$' should do it.
Then take the output of that locate | grep
and run file
on it, and pipe the output of that file command through grep
to find the lines that include the phrase 'core file'.
That gives you lines like
/home/akkana/geology/NorCal/pinnaclesGIS/core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), too many program headers (523)
But those lines are long and all you really need are the filenames; so pass it through sed to get rid of anything to the right of "core" followed by a colon.
Here's the final command:
file `locate core | grep '/core$'` | grep 'core file' | sed 's/core:.*//'
On my system that gave me 11 files, and they were all really core dumps. I deleted them all.
[ 12:54 Feb 19, 2015 More linux | permalink to this entry | ]