脚本1
作用:创建10个1M的文件
1
2
3
4
5
6
|
[root@python script]
# cat make_file.sh
#!/bin/bash
#
for
i
in
$(
seq
1 10);
do
dd
if
=
/dev/zero
of=
/data/test/test
"${i}"
bs=1M count=1
done
|
脚本2
作用:移走/data/test目录下大于100K的普通文件到/tmp目录下
1
2
3
4
|
[root@python script]
# cat file_mv.sh
#!/bin/bash
#
find
/data/test
-
type
f -size +100k |
xargs
-i
mv
{}
/tmp
|
脚本3
作用:删除/tmp目录下包含test的任意字符且大小大于100K的文件
1
2
3
4
|
[root@python script]
# cat file_rm.sh
#!/bin/bash
#
find
/tmp
-name
"test*"
-
type
f -size +100k |
xargs
-i
rm
-f {}
|
脚本4
结合continue,break的for循环示例
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@python script]
# cat for.sh
#!/bin/bash
# for loop egs
for
I
in
{1..10};
do
if
[[ $I -
eq
6 ]];
then
echo
"six six six"
continue
elif
[[ $I -
eq
9 ]];
then
echo
"bye bye 9"
break
fi
echo
$I
done
|
脚本5
简单while循环示例
1
2
3
4
5
6
7
8
|
[root@python script]
# cat while.sh
#!/bin/bash
# while loop egs
NUM=5
while
[[ $NUM -gt 0 ]];
do
echo
$NUM
let
NUM-=1
done
|
脚本6
简单until循环示例
1
2
3
4
5
6
7
8
9
|
[root@python script]
# cat until.sh
#!/bin/bash
# until loop egs
#
NUM=5
until
[[ $NUM -lt 0 ]];
do
echo
$NUM
let
NUM-=1
done
|
脚本7
结合位置参数的case语句用法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@python script]
# cat case.sh
#!/bin/bash
#case loop egs
#
VAR=$1
case
$VAR
in
neo)
echo
hacker
;;
sternberg)
echo
rigorous
;;
michael)
echo
creative
;;
*)
echo
unknow
;;
esac
|
脚本8
function函数示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@python script]
# cat function.sh
#!/bin/bash
#function egs
#
#1st function
function
hi() {
echo
"Hi,you are beautiful!"
}
#sencond function
hello() {
echo
-e
"Jun Lei says\"hello thank you\""
}
hi
hello
|
本文转自 PowerMichael 51CTO博客,原文链接:http://blog.51cto.com/huwho/1958762,如需转载请自行联系原作者