1+2+..+100求和
+--------------+
| for循环 |
+--------------+
sum=0
for((i=1;i<=100;i++))
do
sum=$((i+$sum))
done
echo $sum
+--------------+
| while循环 |
+--------------+
sum=0
i=1
while ((i<=100))
do
((sum+=i))
((i++))
done
echo $sum
+--------------+
| 数学公式 |
+--------------+
i=100
echo $((sum=i*(i+1)/2))
+--------------+
| awk |
+--------------+
seq 100 | awk '{i+=$1}END{print i}'
批量生成8位随机数文件
for((i=1;i<=10;i++))
do
touch `echo $RANDOM | md5sum | cut -c 1-8`.txt
done
批量修改文件名
ll
-rw-r--r-- 1 root root 0 Jul 31 06:57 01508427.txt
-rw-r--r-- 1 root root 0 Jul 31 06:57 177ad50a.txt
-rw-r--r-- 1 root root 0 Jul 31 06:57 764f1747.txt
-rw-r--r-- 1 root root 0 Jul 31 06:57 79205720.txt
-rw-r--r-- 1 root root 0 Jul 31 06:57 8d54c065.txt
-rw-r--r-- 1 root root 0 Jul 31 06:57 97026f8e.txt
+--------------+
| sed |
+--------------+
for i in `ls *.txt`
do
mv $i `echo $i | sed "s@txt@sh@g"`
done
+--------------+
| awk |
+--------------+
for i in `ls *.txt`
do
awk -F. '{print "mv "$0,$1".sh"}'
done
+--------------+
| rename |
+--------------+
for i in `ls *.txt`
do
rename ".txt" ".sh" $i;
done
关闭服务开机自启
chkconfig --list | grep 3:on | awk '{print $1}' |
egrep -v "rsyslog | sshd | sysstst" | sed -r 's@(.*)@chkconfig 1 off@g' | bash