脚本案例

打印一个给定的数字的反序,如输入10572,输出27501

  1. #!/bin/bash
  2. if[ $# -ne 1 ]
  3. then
  4. echo "Usage: $0 number"
  5. echo " I will find reverse of given number"
  6. echo " For eg. $0 0123, I will print 3210"
  7. exit1
  8. fi
  9. n=$1
  10. rev=0
  11. sd=0
  12. while[ $n -gt 0]
  13. do
  14. sd=`expr $n % 10`
  15. rev=`expr $rev \* 10 + $sd`
  16. n=`expr $n / 10`
  17. done
  18. echo "Reverse number is $rev"

2、 将/usr/local/test目录下大于100k的文件转移到/tmp目录下:

#!/bin/bash

for FILE in `ls /usr/local/test`
do
    if [ -f $FILE ] ; then
        if [ `ls -l  $FILE | awk `{print $5}` -gt 100000 ] ; then
            mv $FILE  /tmp/
        fi
    fi
done

~~~~~~~~

#!/bin/bash
for FileName in `ls -l  /usr/local/test | awk '$5>102400' {print $9}`
do
        mv $FileName  /tmp/
done
ls -al  /tmp/
echo  "done!"

posted on 2014-12-10 11:47  寒星12345678999  阅读(191)  评论(0编辑  收藏  举报