zoukankan      html  css  js  c++  java
  • 正则表达式练习题

    1.显示/proc/meminfo文件中以大小s开头的行(要求两种方法)
    cat /proc/meminfo | grep '^[sS]'
    cat /proc/meminfo | grep '^s|^S'

    2.显示/etc/passwd文件中不以/bin/bash结尾的行
    cat /etc/passwd | grep -v "/bin/bash"

    3.显示用户rpc默认的shell程序
    cat /etc/passwd |grep 'rpc' | cut -d'/' -f5-6

    4.找出/etc/passwd中的两位或三位数
    cat /etc/passwd |grep -o '[0-9]{2,3}'

    5.显示centos7的/etc/grub2.cfg文件中,至少以一个空白字符开头且后面有非空白字符的行
    grep '^[[:space:]].+[^[:space:]]' /etc/grub2.cfg

    6.找出netstat -tan命令结果中以LISTEN后跟任意多个空白字符结尾的行
    netstat -tan | grep 'LISTEN[[:space:]]*$'

    7.显示centos7上所有UID小于1000以内的用户名和UID
    cat /etc/passwd |cut -d: -f1,3 |grep '<[0-9]{1,3}>'|sort -t: -k2 //默认正向排序
    cat /etc/passwd |cut -d: -f1,3 |grep '<[0-9]{1,3}>'|sort -t: -k2 -nr //也可对k2列反向排序

    8.添加用户bash、testbash、basher、sh、nologin(其shell为/sbin/nologin),找出/etc/passwd用户名和shell同名的行
    cat /etc/passwd |grep '(^[[:alnum:]]+).*/1$'

    9.利用df和grep,取出磁盘各分区利用率,并从大到小排序
    [16:48:38 root@localhost data]#df |tr -s ' ' |cut -d ' ' -f5-6 |tail -n +2 |sort -k1 -nr
    27% /
    16% /boot
    2% /swap
    2% /run
    1% /run/user/0
    0% /sys/fs/cgroup
    0% /dev/shm
    0% /dev

  • 相关阅读:
    变量和简单的数据类型
    homebrew 取消每次安装检查更新
    小程序设置全屏
    linux 文本换行
    删除mac上的缓存文件
    laravel admin 中监听后台管理数据变化
    laravel快速添加观察者
    软件安装
    跨域数据
    将spring mvc 发布到服务器端
  • 原文地址:https://www.cnblogs.com/HRAS/p/12825860.html
Copyright © 2011-2022 走看看