The Linux find command is awesomely powerful!
The Linux find command is awesomely powerful!
At least I think it is awesome. Here are a couple of useful commands which highlight some of it more powerful features. (these are just ones I used recently, as soon as you start chaining sed, awk, sort and uniq, the commands get even more powerful)
Changing the ownership of all files which do not have the correct ownership (useful to me when doing a server migration where the postfix user was uid 102 and changed to uid 105)
This command also lists the details of the file before it runs the chown command on it.
find . -not -uid 105 -exec chown postfix {} ;
Get a list of all of the files that have been modified in the last 20 minutes
find . -mmin -20
find all log files and their sizes older than 60 days, I use awk to sum the size of these up.
find /data/webs/ -path '*/logs/*' -name '*log' -mtime +60 -exec du {} ; |awk '{t+=$1; print t" "$0}'
Often times I just turn around and delete these files if I do not need them , the command above helps me know what kind of space I would be recovering and if there are any HUGE file size offenders.
find /data/webs/ -path '*/logs/*' -name '*log' -mtime +60 -delete