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 09:01
下一篇 2016-08-12 09:01

相关推荐

  • 创建目录树

    创建目录树 [wing@bogon ~]$ mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,\ sysconfig/network-scripts},\ lib/modules,lib64,proc,sbin,sys,tmp,usr/local{bin,sbin},\ var/{lock,…

    Linux干货 2017-07-24
  • 小懒豆-运维28-01

    1.计算机的组成及其功能
    2.linux的发行版,并描述差异及其联系
    3.说明linux的哲学思想,并按照自己的理解进行解释描述
    4.linux的命令使用格式,并介绍下列命令 ifconfig echo tty startx export pwd history shundown poweroff reboot hwclock date的
    5.如何获取linxux的帮助命令
    6.简述fhs(Filesystem hierarchy standard)

    2017-12-03
  • 第二周作业

    第二周博客作业 1. Linux上常用的文件管理命令及使用 (1) CP命令:复制文件或文件夹语法格式        cp [OPTION]… [-T] SOURCE DEST     …

    Linux干货 2016-12-16
  • 脚本练习

    脚本练习: 1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 #!/bin/bash #功能:编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,…

    Linux干货 2016-08-12
  • Shell脚本编程

    Shell脚本编程

    2017-09-20
  • 马哥教育网络班22期+第九周课程练习

    1. 写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash#declare -a loginuserdeclare -i sum_login=0declare -i sum_nologin=0list=($(cat /et…

    Linux干货 2017-01-03