加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Shell脚本初级练习篇

发布时间:2020-12-15 16:27:58 所属栏目:安全 来源:网络整理
导读:Shell脚本初级练习篇 650) this.width=650;" src="http://img.jb51.cc/vcimg/static/loading.png" title="images.png" alt="wKioL1mdXkfDFzntAAAXoHD3udQ741.png" src="https://s2.51cto.com/wyfs02/M02/9F/7B/wKioL1mdXkfDFzntAAAXoHD3udQ741.png"> 脚本1

Shell脚本初级练习篇

wKioL1mdXkfDFzntAAAXoHD3udQ741.png

脚本1

作用:创建10个1M的文件

[root@pythonscript]#catmake_file.sh
#!/bin/bash
#
foriin$(seq110);do
ddif=/dev/zeroof=/data/test/test"${i}"bs=1Mcount=1
done

脚本2

作用:移走/data/test目录下大于100K的普通文件到/tmp目录下

[root@pythonscript]#catfile_mv.sh
#!/bin/bash
#
find/data/test-typef-size+100k|xargs-imv{}/tmp

脚本3

作用:删除/tmp目录下包含test的任意字符且大小大于100K的文件

[root@pythonscript]#catfile_rm.sh
#!/bin/bash
#
find/tmp-name"test*"-typef-size+100k|xargs-irm-f{}

脚本4

结合continue,break的for循环示例

[root@pythonscript]#catfor.sh
#!/bin/bash
#forloopegs
forIin{1..10};do
if[[$I-eq6]];then
echo"sixsixsix"
continue
elif[[$I-eq9]];then
echo"byebye9"
break
fi
echo$I
done

脚本5

简单while循环示例

[root@pythonscript]#catwhile.sh
#!/bin/bash
#whileloopegs
NUM=5
while[[$NUM-gt0]];do
echo$NUM
letNUM-=1
done

脚本6

简单until循环示例

[root@pythonscript]#catuntil.sh
#!/bin/bash
#untilloopegs
#
NUM=5
until[[$NUM-lt0]];do
echo$NUM
letNUM-=1
done

脚本7

结合位置参数的case语句用法

[root@pythonscript]#catcase.sh
#!/bin/bash
#caseloopegs
#
VAR=$1
case$VARin
neo)
echohacker
;;
sternberg)
echorigorous
;;
michael)
echocreative
;;
*)
echounknow
;;
esac

脚本8

function函数示例

[root@pythonscript]#catfunction.sh
#!/bin/bash
#functionegs
#
#1stfunction
functionhi(){
echo"Hi,youarebeautiful!"
}

#sencondfunction
hello(){
echo-e"JunLeisays"hellothankyou""
}
hi
hello

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读