码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本 回顾 小练习

时间:2016-11-25 01:09:08      阅读:384      评论:0      收藏:0      [点我收藏+]

标签:zha   字符   find   log   awk   bash   amp   let   模式   

1.把/OPT目录下(包含子目录)下所有后缀为“.sh”的文件后缀变更为“.shell”
2.将A、B、C目录下的文件A1、A2、A3文件改名为A4、A5、A6
3.如何在vi模式下将文件中的aa字符串批量改成bb

 

1.

#!/bin/bash
dir=/hanzhao
files=`find /hanzhao/ -name ‘*.sh‘`
for file in $files
do
# echo $file
 filename=${file%.*}
# echo $filename
 mv $file ${filename}.shell
done

2.

#!/bin/bash
    file=`ls /[ABC]/A[123]`
    for i in $file        
        do
        num=${i##*A}
        let num1=num+3 
       # echo $num1
       # num2=${i%A*} 
       # echo $num2 
        mv $i ${i%A*}A$num1
    done

3.

直接用vi打开文件,之后再读模式下 直接输入 :%s#aa#bb#g

 4备份每天的日志

#!/bin/bash
cp /opt/lampp/logs/access_log /opt/bak_access_log-`date +%Y%m%d%H%M`
>/opt/lampp/logs/access_log

 5.启动停止 lampp

#!/bin/bash
start=0
pidnum=`ps aux|grep "/opt/lampp/*"|wc -l`
echo ${pidnum}
if [ ${pidnum} -gt 1 ]
then 
echo ‘lampp is start‘
read -p ‘Do you wish to stop lampp? y or n:  ‘ yn
case $yn in
[Yy]* )start=1;;
[Nn]* )exit;;
 * )echo ‘Please answer Y or N‘
exit;;
esac
else
echo ‘lampp is stop,doing start‘
read -p ‘Do you wish to start lampp? y or n:  ‘ yn
case $yn in
[Yy]* )start=0;;
[Nn]* )exit;;
 * )echo ‘Please answer Y or N‘
exit;;
esac
fi

if [ ${start} -eq 1 ]
then ps aux|grep "/opt/lampp/*"|grep -v "grep"|awk ‘{print $2}‘|xargs kill -9
echo ‘lampp is stop‘
else 
/opt/lampp/lampp start
echo ‘lampp is start‘
fi

 

 

shell脚本 回顾 小练习

标签:zha   字符   find   log   awk   bash   amp   let   模式   

原文地址:http://www.cnblogs.com/hanzhao1987/p/6099922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!