Tips and Tricks with Find

1 minute read

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

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

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

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

Find files larger than 500MB in size

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

Find files larger than 500M and then delete them

1
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

1
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.

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

Tags:

Categories:

Updated: