Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1898034
  • 博文数量: 383
  • 博客积分: 10011
  • 博客等级: 上将
  • 技术积分: 4061
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-24 18:53
文章分类

全部博文(383)

文章存档

2011年(1)

2010年(9)

2009年(276)

2008年(97)

我的朋友

分类: LINUX

2008-12-14 17:13:57

1.whereis 和 which 的区别
  which: 只在PATH环境变量中寻找文件
  whereis: 在系统定义的目录中寻找
 
2.根据关键字查找man页
  举例:apropos split  或者  man -k split
 
3.sed示例:
  sed -e s/root/toor/g /etc/passwd > ~/test.out         替换 /etc/passwd中的root为toor输出到~/test.out
  sed -e 's/root/toor/g; s/ftp/ptf/g' /etc/passwd       使用 -e 指定多个命令
  sed -e 's/root/toor/g' -e ' s/ftp/ptf/g' /etc/passwd  同上
  使用命令文件:
  /* test.sed 开始,不包含本行 */
  s/root/toor/g
  s/ftp/ptf/g
  /* test.sed 结束,不包含本行 */
  指令:sed -f test.sed /etc/passwd
 
4.awk示例:
  awk '{print $0}' /etc/passwd                          $0表示完整的输入记录
  awk -F":" '{print $1}' /etc/passwd                    打印第一列,以:为分隔符
  awk -F":" '{print "username: "$1 "\t\t\t user id: "$3}' /etc/passwd        格式化并打印
  使用命令文件:
  /* test.awk 开始,不包含本行 */
  BEGIN{
        FS=":"
  }
  {printf "username: "$1 "\t\t\t user id: "$3"\n"}
  END{
        printf "all done processing /etc/passwd\n"
  }
  /* test.awk 结束,不包含本行 */
  指令:awk -f test.awk /etc/passwd
 
 
5.shell脚本
  1)特殊变量:
      ?前一个命令输出状态
      0当前脚本名
      1~9参数
  2)范例1,使用if语句
    #!/bin/bash
 
    echo "guest the select color"
    read COLOR
 
    if [ $COLOR = "yellow" ] 
    then
            echo "you are correct"
    elif [ $COLOR = "blue" ]
    then
            echo "you are correct also"
    fi
 
  3)范例2,使用case语句
    #!/bin/bash
 
    case "$1" in
        start)
                echo "start......"
                ;; 
        stop)
                echo "stop......"
                ;; 
        status)
                echo "status......"
                ;; 
        *) 
                echo "usage: $0 {start | stop | status}"
                ;;  
    esac
 
  4)范例3,使用迭代流程
    #!/bin/bash
 
    echo "guest color: red, blue or orange\n"
    read COLOR
 
    while [ $COLOR != "orange" ]
    do
            echo "incorrect, try again"
            read COLOR
    done
 
    echo "correct"
 
  5)使用双引号进行命令替换
    lines="$(wc -l 3.sh)"
    echo $lines
 
  6)测试文件
    -d file        目录
    -e file        存在
    -r file        可读
    -w file        可写
    -x file        可执行
 
阅读(575) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~