---
title: "shell 命令 find "
author: "dingjun1"
date: "2013-05-23T15:59:56Z"
tags: []
categories: ["编程语言"]
slug: "shell-find"
draft: false
lastmod: "2013-05-23T15:59:56Z"
id: 1874144
url: "https://dingjun1.iteye.com/blog/1874144"
---

deal_log.sh

```shell


#! /bin/bash
find /home/*/* -maxdepth 4  -regex ".+\(\.log\|catalina\.out\)\(\.[\d\-]*\)?" -exec ./deal_file.sh {} \; 
find /opt/logs -type f -regex ".+\.log\(\.[0-9\-]*\)?" -exec ./deal_file.sh {} \; 


```



deal_file.sh

```shell

#! /bin/bash
logfile="clean_log.`date  +%Y-%m-%d`"
curfile=$1
if  ( echo "$curfile" | grep -e '\.log$' -e 'catalina\.out$' > /dev/null ) ;
then
size=`du -h $1 | awk '{ print $1 } '`
echo "" > $1
echo "clean file "$1 "size:" `du -h $1 | awk '{ print $1 } '`" old size:"$size >> $logfile;
else
echo "rm file" $1 `du -h $1 | awk '{ print $1 } '` >> $logfile;
rm -v $1
fi

```