shell 练习题(7)

  1. 显示/etc/rc.d/rc.sysinit文件中,以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

    # grep "^#[[:space:]]\{1,\}[^[:space:]]\{1,\}" /etc/rc.d/rc.sysinit
    
  2. 显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

    # grep "^[[:space:]]\{1,\}[^[:space:]]\{1,\}" /boot/grub/grub.conf
    
  3. 找出/etc/passwd文件中一位数或两位数;

    # grep --color=auto "\<[0-9]\{1,2\}\>" /etc/passwd
    
  4. 找出ifconfig命令结果中的1到255之间的整数;

    # ifconfig | grep -E --color=auto "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
    
  5. 查看当前系统上root用户的所有信息;

    # grep "^root\>" /etc/passwd
    
  6. 添加用户bash和testbash、basher,而后找出当前系统上其用户名和默认shell相同的用户;

    # grep --color=auto "^\([[:alnum:]]\{1,\}\)\>.*\1$" /etc/passwd
    
  7. 找出netstat -tan命令执行的结果中以“LISTEN”或“ESTABLISHED”结尾的行;

  8. 取出当前系统上所有用户的shell,要求:每种shell只显示一次,且按升序显示;
    # cut -d: -f7 /etc/passwd | sort -u

 (答案后续完善)

猜你喜欢

转载自blog.csdn.net/weixin_38280090/article/details/82113428