首页 > 代码库 > shell脚本 回顾 小练习
shell脚本 回顾 小练习
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脚本 回顾 小练习
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。