Вопрос

Core files are generated when a program terminates abnormally. It consists the working memory of the system when the program exits abnormally. You can use a debugger with the generated core file to debug the program. The Challenge is:

  1. Delete all core files from a directory (recursive search). Core files are quite huge in size and you may want to delete them to save memory
  2. Make sure you don't delete any folder named core and some other filed named core which not actually a memory/system dump
Это было полезно?

Решение

After some searching on the internet, I found a nice piece of code to do this. Drawback is it asks you to recognize the core file to make sure its not some other file named core. Source : http://csnbbs.com/

Code:

find . -name core\* -user $USER -type f -size +1000000c -exec file {} \; -exec ls -l {} \; -exec printf "\n\ny to remove this core file\n" \; -exec /bin/rm -i {} \;

Please post if you have better solutions.

Другие советы

To delete all files matching to the regex "*.core" you can use:

find . -name "*.core" -type f  -delete

find supports many filters like:

-size +1000000c # size > 1G

-user $USER # specific user

-mtime +3 # older than 3 days

if you are afraid for files ending with "core" that are not core files you can filter by file command piped to some other linux commands. for example -

find . -name "*.core" -type f -exec file {} \; | grep 'core file' | awk -F":" '{print $1}' | xargs -n1 -P4 rm -rf

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top