WordPress Developer & Linux Administrator

Find and remove all core files on your server

Depending on your server configuration, you may find the some of your websites have “core” files that you don’t remember putting there. A core file is an image of a process that is created by the operating system when the process terminates unexpectedly. This file can be very useful in determining what went wrong with a process. The production of core files can be enabled by default, depending on the distribution and version of Linux® that you have. However, most of the time you don’t care and just want them gone. I’m going to show you how to easily remove them.

Step 1: Find the files

I recommend trying to locate and view the files before actually attempting to remove them. Also, rather than trying to run this on ‘/’ (root), you’re probably a little safer running it on the ‘/home’ directory instead.

# Find all core files
find /home -type f -regex ".*/core.[0-9][0-9][0-9][0-9]"

Step 2: Remove the offending files for a single user first, as a test

Use caution with this, and it’s a good idea to test it once on your server for a single user’s home directory, rather than the entirety of the ‘/home’ area. Couldn’t hurt to backup the user’s ‘/home/user’ directory before running it.

# Backup the directory first
cd /home/user tar pcvzf ../user.tar.gz .

# Try deleting the core files on that user's directory
find /home/user -regex '.*/core.[0-9]*$' -exec rm -f {} \;

Step 3: If the command worked and didn’t harm anything, run it for all users

# Find and delete all core files
find /home -regex '.*/core.[0-9]*$' -exec rm -f {} \;

These guides and tutorials were initially intended to serve as a dumping ground for things I commonly need to refer to, but I’ll be growing these on the website over time. I hope these articles are of use to anyone visiting.

Categories: CommandsTags: , , ,


Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.