我發現漸漸喜歡上寫腳本,這裏記錄一些實際用到的「漂亮」的腳本。java
day=$1 ls -l | awk '{if($7=='"$day"') print $9}' | xargs rm
$7是日期列,$9是文件名列shell
ps -ef | grep zookeeper | grep -v grep | awk '{print $2}' | xargs kill -9
awk很是實用,寫出的腳本簡潔,有效,配合xrags更加高效bash
grep 'key' filename | wc -l //匹配開頭、結尾 grep ^024$ get.log | wc -l
svn st | awk '{if($1=="M") print $2}' | grep -v metrics | xargs svn commit -m "ref #34454 @8h"
find . -name "*.jar"|awk '{print "jar -tvf "$1}' | sh | grep 'Class Name'
遞歸的查找當前路徑下全部jar包中全部類名爲‘Class Name’的類。服務器
ip=(ip1 ip2 ip3) for loop in ${ip[@]}; do scp -r /opt/java/jdk1.7.0_60 username@${loop}:/opt/java/jdk1.7.0_60; done;
ps: 這幾臺機器最好設好免密登錄,要否則要一臺一臺輸密碼。svn
ls -t $dataLogDir/log.* | tail -n +$count | xargs rm -f