免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 639 | 回复: 0
打印 上一主题 下一主题

linux学习的一些记录(原创) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-13 21:36 |只看该作者 |倒序浏览
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 开始,不包含本行 */
[color="#ff00ff"]  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语句
[color="#ff00ff"]    #!/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语句
[color="#ff00ff"]    #!/bin/bash

    case "$1" in
        start)
               
echo "start......"
                ;;  
        stop)
               
echo "stop......"
                ;;  
        status)
               
echo "status......"
                ;;  
        *)  
               
echo "usage: $0 {start | stop | status}"
               
;;  
    esac

  4)范例3,使用迭代流程
[color="#ff00ff"]    #!/bin/bash

    echo "guest color: red, blue or
orange\n"
    read COLOR

    while [ $COLOR != "orange"
]
    do
            echo "incorrect, try again"
            read
COLOR
    done

[color="#ff00ff"]    echo "correct"

  5)使用双引号进行命令替换
    lines="$(wc -l 3.sh)"
    echo $lines

  6)测试文件
    -d file        目录
    -e file        存在
    -r file        可读
    -w file        可写
    -x file        可执行

               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/33098/showart_258100.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP