从Linux小白到大牛——与狼共舞的日子5

马哥教育网络班21期+第5周课程练习

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行。


[root@localhost ~]# grep '^[[:space:]]\+' /boot/grub/grub.conf

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


[root@localhost ~]# grep '^#[[:space:]]\+[^[:space:]]' /etc/rc.d/rc.sysinit

3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行。


[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"

4、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息。


[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
[root@localhost ~]# grep '^\([[:alnum:]]\+\>\).*\1$' /etc/passwd

5、显示当前系统上root、fedora或user1用户的默认shell。


[root@localhost ~]# egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f1,7

6、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello()。


[root@localhost ~]# egrep -o '^[_[:alpha:]]+\(\)' /etc/rc.d/init.d/functions

7、使用echo命令输出一个绝对路径,使用grep取出其基名。扩展:取出其路径名。


[root@localhost ~]# echo '/a/b/c' | egrep -o '[^/]+/?$' | cut -d'/' -f1


[root@localhost ~]# echo /a/b/c/ | egrep  -o   '^/\<.*/\<'

8、找出ifconfig命令结果中的1-255之间数字。


[root@localhost ~]# ifconfig | egrep -o '\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>'

9、挑战题:写一个模式,能匹配合理的IP地址。


[root@localhost ~]# ifconfig | egrep -o "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

10、挑战题:写一个模式,能匹配出所有的邮件地址。


[root@localhost ~]# echo aa@126.com |  grep '[[:alnum:]]\+@[[:alnum:]]\+\.[[:alnum:]]\+$'

11、查找/var目录下属主为root,且属组为mail的所有文件或目录。


[root@localhost ~]# find /var -user root -a -group mail

12、查找当前系统上没有属主或属组的文件。进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录。


[root@localhost ~]# find / -nouser -a -nogroup


[root@localhost ~]# find / -nouser -a -nogroup -a -atime -3

13、查找/etc目录下所有用户都有写权限的文件。


[root@localhost ~]# find /etc -perm -333

14、查找/etc目录下大于1M,且类型为普通文件的所有文件。


[root@localhost ~]# find /etc -size +1M -type f

15、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件。


[root@localhost ~]# find /etc/init.d -perm -113

16、查找/usr目录下不属于root、bin或hadoop的文件。


[root@localhost ~]# find /usr -not -user root -a -not -user bin -a -not -user hadoop

17、查找/etc/目录下至少有一类用户没有写权限的文件。


[root@localhost ~]# find /etc -not -perm -333

18、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件。


[root@localhost ~]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop

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

(0)
N21_孤狼N21_孤狼
上一篇 2016-08-31 16:24
下一篇 2016-08-31 20:54

相关推荐

  • yum

    yum yum:YellowdogUpdate Modifier,rpm的前端程序,可解决软件包相关依赖性,可在多个库之间定位软件包,up2date的替代工具 yum repository: yum repo,存储了众多rpm包,以及包的相关的元数据文件(放置于特定目录repodata下)文件服务器:http://https://ftp://file:// …

    2017-08-17
  • 磁盘管理之文件系统

                             文件系统     文件系统是操作系统用于…

    Linux干货 2016-09-06
  • 文本处理工具练习及作业

    练习1: 1、找出ifconfig “网卡名” 命令结果中本机的IPv4地址 ifconfig |head -n 2 |tail -n 1|tr -s ” ” : |cut -d: -f4 2、查出分区空间使用率的最大百分比值 df|tr -s ‘ ‘ %|sort -t% -k5 -n|tail -n 1|c…

    2017-07-29
  • 马哥教育网络班19期第七周课程练习

    第七周作业 1.创建一个10G分区,并格式化为ext4文件系统:   (1)要求甘block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl;   (2)挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@nginx ~]# fdisk /dev/sdd D…

    Linux干货 2016-06-23
  • 8月5日第七节课作业

    一、当天练习 1、找出ifconfig命令结果中本机的所有IPv4地址 2、查出分区空间使用率的最大百分比值 3、查出用户UID最大值的用户名、UID及shell类型 4、查出/tmp的权限,以数字方式显示 5、统计当前连接本机的每个远程主机IP的连接数,并按从大 到小排序 1、显示/proc/meminfo文件中以大小s开头的行;(要求:使 用两种方式) …

    Linux干货 2016-08-08
  • 基于key验证和一些自动化运维工具

    pssh pscp.pssh Pslurp.pssh AIDE等

    2018-01-16

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-07 17:42

    非常的漂亮,如果能解释一下各命令的参数意义就更好了,加油。