grep作业题

找出/proc/meminfo文件中,所有以大写或小写s开头的行,至少三种方式:

grep -i "^s" /proc/meminfo

grep "^[sS]" /proc/meminfo

grep -E "^(s|S)" /proc/meminfo


显示当前系统上roo、centos或者user用户的相关信息

grep -E "^(root/centos/user)\>" /etc/passwd


找出/etc/rc.d/init.d/functions文件中行首为某单词(包括下划线)后面跟一个小括号的行

grep -E -o "[_[:alnum:]]+\(\)" /etc/rc.d/init.d/functions


使用echo命令输出一绝对路径,使用egrep取出基名

echo /etc/sysconfig/ | grep -E -o "[^/]+/?$"


找出ifconfig命令结果中1-255之间的数值

ifconfig | grep -E -o "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"  | 这算的是每一位的数字。


找出ifconfig命令结果中所有IPv4地址

个位    十位  百位100以上  百位

ifconfig | grep -E -o "(\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>\.)(\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>\.){2}\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"

ifconfig|  grep -E -o "(\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>\.){3}(\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>)"


这里,255 广播地址待议。25[0-5] 这里我觉的第一个用254


找出/etc/passwd文件中用户名同shell名的行

grep -E "^([^:]+\>).*\1$" /etc/passwd


找出ifconfig eth0 的ip地址

ifconfig eth0 | grep "inet addr" | cut -d: -f 2|cut -d " " -f 1  只能用一个空格来切


匹配右邮箱:

grep '.*@.*\.[[:alpha:]]\+$'


原创文章,作者:helloworld,如若转载,请注明出处:http://www.178linux.com/33398

(0)
helloworldhelloworld
上一篇 2016-08-12
下一篇 2016-08-12

相关推荐

  • 网络配置的常用工具

    一、网络配置的常用工具     例如:                ifcfg:ifconfig、route、netstat    &nb…

    Linux干货 2016-09-09
  • N22期-第五周博客作业

    1、显示当前系统上root、fedora或user1用户的默认shell; [root@localhost jimmy]# egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f7 /bin/bas…

    Linux干货 2016-09-10
  • Centos6搭建vsftpd手册

    1、开启防火墙ftp端口vi /etc/sysconfig/iptables     #编辑防火墙配置文件 1 -A INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT(允许21端口通过防火墙) 2 -A INPUT -m st…

    Linux干货 2017-04-26
  • linux基础之用户管理

    介绍了一些基础命令,比如cut、head传输到管道时的使用,并通过详细的介绍、大量的习题完成了用户管理的相关知识

    Linux干货 2017-12-15
  • 进程管理,计划任务

    一、进程相关概念及系统管理工具     进程概念         内核的功用:进程管理、文件系统、网络功能、内存管理、驱动程序、 安全功能等         P…

    Linux干货 2016-09-18
  • N25-第三周作业

    第三周作业 1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 ~]#who | cut -d' ' -f 1 | sort | uniq 2、取出最后登录到当前系统的用户的相关信息。 ~]#who |tail -1 3、取出当前系统上被用户当作其默认shell的最多的那个shell。 ~]#cat…

    Linux干货 2016-12-18