zoukankan      html  css  js  c++  java
  • linux 入门测验

    cd . 当前目录.. 返回上一级目录 ../../../返回多级目录

    grep "目标信息" 目标地址

      -v :显示没有被匹配的信息

    mkdir
      -p:创建多级目录 mkdir -p /oldboy/test/
      目录存在也可以反复创建目录命令,不会出现报错
    alias 别名
      临时取消别名 后面添加命令 或者 /bin/cp jia 加上命令
      临时添加命令 alias grep="grep --color"
      永久取消别名 vi ~/.bashrc 删除设置别名那一行
      永久添加别名 vi ~/.bashrc 添加一行命令alias grep="grep --color" 保存后source alias
      企业实践:给危险的rm命令设置保险措施(设置别名)
    第一个里程:临时配置别名
      alias rm='echo "datainfo can not del"'
    第二个里程:编写配置文件,使之别名功能永久生效
      echo "alias rm='echo "datainfo can not del"'" >>/etc/profile
      [root@shhaioldboy02-LNB ~]# tail -1 /etc/profile
      alias rm='echo datainfo can not del'
    第三个里程:加载配置文件
      source /etc/profile
    第四个里程:取消默认系统的别名功能(rm)
      PS:系统中的一些默认配置,建议编辑时不要删除掉,可以临时注释掉
      vim /root/.bashrc
      #alias rm='rm -i'

    vi/vim
      i 从当前行的行首进行编辑
      o 从当前行的后一行
      O 从当前行的前一行
      u 还原上个操作
      g 快速切换到首行
      G 快速切换到尾行
      系统中默认设置不建议删除,建议注释。
      别名单引号里面一定是命令 需要英文格式
    三剑客取行
      sed -n "20,30p" ett.txt -i 替换文件内容信息 s 搜索到要替换的文件信息 g全局搜索要替换的内容
      awk 'NR==20,NR==30' ett
      grep -A10 "20" ett.txt 从前往后取10行
      grep -B10 "30" ett.txt 从后往前取10行
      grep -C5 "25" ett.txt 从中间取行
    实例:
      只查看ett.txt文件(共50行)内第20到第30行的内容
      创建模拟环境创建50行信息
      seq 50 >/root/data/ett.txt
      第一种方式:利用sed命令
        [root@shhaioldboy02-LNB ~]# sed -n '20p' /root/data/ett.txt
        20
        [root@shhaioldboy02-LNB ~]# sed -n '20,30p' /root/data/ett.txt
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
      第二种方式:利用awk命令
        [root@shhaioldboy02-LNB ~]# awk 'NR==20' /root/data/ett.txt
        20
        [root@shhaioldboy02-LNB ~]# awk 'NR==20,NR==30' /root/data/ett.txt
        20
        21

        22
        23
        24
        25
        26
        27
        28
        29
        30
        [root@shhaioldboy02-LNB ~]#
    第三种方法:利用grep命令
        [root@shhaioldboy02-LNB ~]# grep "20" /root/data/ett.txt
        20
        [root@shhaioldboy02-LNB ~]# grep -A10 "20" /root/data/ett.txt
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        [root@shhaioldboy02-LNB ~]# grep "30" /root/data/ett.txt
        30
        [root@shhaioldboy02-LNB ~]# grep -B10 "30" /root/data/ett.txt
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30

        [root@shhaioldboy02-LNB ~]# grep "25" /root/data/ett.txt
        25
        [root@shhaioldboy02-LNB ~]# grep -C5 "25" /root/data/ett.txt
        20
        21
        22
        23
        24
        2    5
        26
        27
        28
        29
        30
      第四种反法 head -n 30 ett.txt|tail -ll 完成打印
      第五种 :VI编辑器 行号设置:set nu 取消行号设置nonu
      寻找文件并且替换:
        sed ’s#目标文件#替换内容#g‘ -i 谨慎使用!!!!
        instead ----代替!--lalala---!
        find ./text/del.sh -type f name "*.sh"
        [root@shhaioldboy02-LNB oldboy]# sed 's#oldboy#oldgirl#g' /oldboy/test/del.sh
        oldgirl
        [root@shhaioldboy02-LNB oldboy]# cat /oldboy/test/del.sh
        oldboy
        [root@shhaioldboy02-LNB oldboy]# sed -i 's#oldboy#oldgirl#g' /oldboy/test/del.sh
        [root@shhaioldboy02-LNB oldboy]# cat /oldboy/test/del.sh
        oldgirl
        
    补充:利用sed命令修改文件时,规范使用方法
      01. 在修改前,先模拟执行测试替换功能(不要直接加上-i参数)
      02. 在修改前,进行文件备份
      sed -i.bak 's#oldgirl#oldboy#g' /oldboy/test/del.sh
    说明:-i参数后不要在接上任何其他参数信息,其他参数要写在-i参数之前

    综合:

    第一种反法 find ./text/del.sh -type f name "*.sh" |xargs sed 's#oldboy#oldgirl#g'
      find ./text/del.sh -type f name "*.sh" |xargs cat
    第二种方法sed -i.bak 's#oldbaoy#oldgil#g' $(find /oldbaoy/ -type f -name "*.sh")
    第三种方法find /oldbaoy/ -type f -name "*.sh" -exec sed -i "s#oldboy#oldgirl#g" {} ;
      -exec 将find命令找出的信息给后面的命令执行
      find ./ type f -name "*.log" -exec rm -f {} ;

    人生就像一滴水,非要落下才后悔! --kingle
  • 相关阅读:
    python模块添加
    Python 的列表排序
    python中文处理问题
    排序算法堆排序
    搜索二分搜索
    排序算法(随机)快速排序(递归)
    排序算法计数排序
    OO设计原则总结
    异常控制以及进程调度
    ubuntu12.04 alternate win7 双系统安装
  • 原文地址:https://www.cnblogs.com/kingle-study/p/9290131.html
Copyright © 2011-2022 走看看