Other Articles

Tips and Tricks with Find

How to use the find command, to make your life easier on the linux or unix cli

Over the years, I’ve managed thousands of websites at once, so I’ve found myself in the position where I need to perform some investigative tasks like

  1. Find old directories and how big they are.
  2. Find all the debug.log files that WordPress generates.
  3. Find any file larger than a specific size.
  4. Change a bunch of configuration files at once.

Find directories older than 30 days and tell me how big they are

find . -maxdepth 1 -mtime +30 -type d -exec du -sh {} \;

Find all debug.log files along with the size of the files

find . -name debug.log -type f -exec du -sh {} \;

Find files larger than 500MB in size

find . -size +500M -type f -exec du -sh {} \;

Find files larger than 500M and then delete them

find . -size +500M -type f -exec rm {} \;

Go through a bunch of config files and change a setting in all of them. This is an example of php-fpm pools

find . -type f -name "*.conf" -exec sed -i 's/pm.max_children = 15/pm.max_children = 1/g' {} \;

Similar as above but for wp-config files. This will change the ip address a constant points to

find . -type f -name "wp-config.php" -exec sed -i 's/10.84.72.76/10.223.242.21/g' {} \;