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
原文:http://www.cnblogs.com/hanzhao1987/p/6099922.html