天天看點

find指令小結

背景:由于機器上log日志比較多,是以想寫個腳本定時清理日志

find  /apps/logs/log_receiver -mtime +7 -name "*[log|err]" -exec rm -f {} \;

使用find指令來做這個事情

find [-H] [-L] [-P] [path...] [expression]

find 目錄路徑

-mtime 天數,+7表示7天前

-name 檢視檔案名字 可以使用通配符

-exec 執行shell腳本 {} \; 這為固定模式;

處理過程中發現一個奇怪的問題:

find /apps/logs/log_receiver/ -mtime +2 -name "*.err" -o  -name "*.log" -exec rm -f {} \;

上面的指令隻能删除log日志,不能清除err

-o == or,或

用-o最好跟()結合,有優先級處理

應該為:

find /apps/logs/log_receiver/ -mtime +2 \( -name "*.err" -o  -name "*.log" \) -exec rm -f {} \;

如果沒有-exec預設為-print列印出來而已

等同于

find /apps/logs/log_receiver/ -mtime +2 -name "*.err"-print -o  -name "*.log" -exec rm -f {} \;

其他可以參考man find

http://www.cnblogs.com/wanqieddy/archive/2011/06/09/2076785.html

雖千萬人,吾往矣!

上一篇: QPS的計算
下一篇: iptables