Finding large files on Linux

I had a client running out of disk space, and support gave me the command to find all the big stuff. This is to find files larger than 10MB. It prints a list ordered by smallest to largest.

sudo find / -mount -noleaf -type f -size +10000k -print0 | xargs -0 ls -lhSr | perl -ne ‘/(\S+\s+){4}(\S+)\s+(\S+\s+){3}(.*)/ and printf(“%*s %s\n”,7,$2.”:”,$4);’

One thing to note is that this didn’t include mailboxes… they must be stored somewhere else on this particular server. The culprit in this case turned out to be a mailbox that was 15GB (!!). 

Dejunking WordPress options

While investigating a slow WordPress installation, I came across this post on how to check if autoloaded options are a factor in the slowdown.

How To Remove Unwanted Autoloaded Data on a WordPress Website

I had no idea that plugins would leave so much junk behind! Here are the two queries to investigate. One to see how big the total options are, and the second to find the worst offenders.

SELECT SUM(LENGTH(option_value)) as autoload_size FROM wp_options WHERE autoload=’yes’;

SELECT LENGTH(option_value),option_name FROM wp_options WHERE autoload=’yes’ ORDER BY length(option_value) DESC LIMIT 15;

For the site I was working on, I set the unnecessary options to autoload=’no’ … just in case it would affect the site.

Spam comments on media attachment pages

One of our clients was getting spam comments on her media attachment pages, so I found this handy little plugin to make it so the attachment pages are no longer available for those kinds of shenanigans. It solves the problem nicely by redirecting each page to the media file itself.

Disable Media Pages

A similar feature is available in Yoast SEO, so if you have that plugin, you can go to SEO -> Search Appearance -> Media tab and turn on the option to Redirect attachment URLs. Sweet!