My computer at work has a tendency to generate an excessive amount of core files, which can be useful for debugging, but slowly take up all of the available space on my computer. I made this command to delete all the core files, given that they all start with "core."
locate /core. | grep -v core.h | grep -v core.c | grep -v core.py \
| grep -v core.xml | grep -v core.txt | grep -v .gz \
| grep -v core.so | grep -v chrome |sudo xargs rm
It works, but it's unwieldy and would delete say core.sh if that file existed on my computer. I think a better way would be:
- Use locate to find all the files starting with "core."
- Feed that list into
file - Make a list out of everything that
filesays is a core file. Assuming that a file is a core file if and only if the output offile file_namecontains the phrase "ELF 64-bit LSB core file x86-64". - Feed that to
sudo xargs rm
But I don't know how to step three in that list.
findand use that instead oflocatefor several reasons. Withfindyou can probably do everything at once. And please if you want to usefileto check the type, provide us an example output offilethat shows one of those core files you want to delete. – Byte Commander Sep 10 '15 at 19:30file file_namecontains the words "ELF 64-bit LSB core file x86-64". – Joshua Snider Sep 10 '15 at 19:41-vflag means reverse matching, i.e., ignore those extensions. Perhaps it would be more efficient to define which exact files you do want to keep – Sergiy Kolodyazhnyy Sep 10 '15 at 20:41man setrlimit,man bash– waltinator Sep 18 '15 at 22:16