DevOps by Default Blog

Find all files larger that X on Linux

This example is for larger than 1GB…

find /home -size +1000000k -exec du -sh {} \;

if they are logs, you might want to truncate them…

/usr/local/bin/trunc_our_app_logs.sh

#!/bin/bash


# NG20110329 - To trunc those pesky logs
# ... trailing slashes are best as they work with symlinks


find /opt/our_app/logs/ -name "*log.*" -mtime +7 -exec rm {} \;
find /opt/our_app/logs/ -size +1000000k -exec cp -f /dev/null {} \;
find /etc/httpd/logs/ -size +500000k -exec cp -f /dev/null {} \;
server101:/home/ec2-user> crontab -e
# Remove/trunk old/large logs. Added by NG20110329.
0 13 * * * /usr/local/bin/trunc_our_app_logs.sh >/dev/null >2&1


crontab: installing new crontab
server101:/home/ec2-user>


#
# Trunk the logs. NG20110429
#
0 23 * * * find /home -name "*.log" -size +1000000k -exec cp -f /dev/null {} \; >/dev/null 2>&1
#

Comments