With this I can find and delete core dumps. Uses find to find files that match the pattern of core. followed by 1-8 digits, then uses file to list the file attributes, and pipes to grep to look for the string core file to confirm it is a core dump. Then use sed to extract the file name from the file output. Store the list of files in a variable; check the list to make sure it looks ok, then pipe into rm via xargs:
core_files_to_delete=$(
file `find -type f -regextype posix-extended -regex ".+/core\.[0-9]{1,8}"` |
grep "core file" |
sed 's/\(.*\/core[.][0-9]\{1,8\}\):.*/\1/'
)
# list the files, do a manual inspection
echo "$core_files_to_delete" | xargs ls -lh
# See the total size in bytes
echo "$core_files_to_delete" | xargs ls -lrt | awk '{ total += $5 }; END { print total }'
# delete them
echo "$core_files_to_delete" | xargs rm
With this I can find and delete core dumps. Uses
findto find files that match the pattern ofcore.followed by 1-8 digits, then usesfileto list the file attributes, and pipes to grep to look for the stringcore fileto confirm it is a core dump. Then usesedto extract the file name from thefileoutput. Store the list of files in a variable; check the list to make sure it looks ok, then pipe intormviaxargs: