马哥教育网络班22期+第五周课程练习

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

 ~]# cat /etc/passwd |grep -E  "^(root|fedora|user1)" |awk -F: '{print $NF}'
/bin/bash
/bin/bash
/bin/bash

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

~]# grep -o "\<[[:alpha:]]\+\>()" /etc/rc.d/init.d/functions 
checkpid()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
success()
failure()
passed()
warning()
action()
strstr()
confirm()

3、使用echo命令输出一个绝对路径,使用grep取出其基名;

 ~]# echo /etc/rc.d/rc.sysinit |grep -o "[^/]\+/\?$"
rc.sysinit
  • 扩展:取出其路径名

~]# echo /etc/rc.d/rc.sysinit |grep -o ".*/"
/etc/rc.d/

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

 ~]# ifconfig |grep -o "[0-9]\|[1-9][0-9]\|[1-9][0-9][0-9]\|2[0-4][0-9]\|25[0-5]
"
0
0
0
0
29
8
4
56
192
168
80
100
192
168
80
255
255
255
...

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

 ~]# 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])"
192.168.80.100
192.168.80.255
255.255.255.0
127.0.0.1
255.0.0.0

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

~]# egrep -i "[[:graph:]]+@[[:graph:]]+\.[a-z]+" 1.txt 

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

~]# find /var -user root -a -group mail -ls
260454    4 drwxrwxr-x   2 root     mail         4096 Sep 16 06:29 /var/spool/mail
264333    8 -rw-------   1 root     mail         5435 Sep 10 08:19 /var/spool/mail/root

8、查找当前系统上没有属主或属组的文件;

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

~]# find /  -not \( -user -o -group \)
~]# find /  -not \( user -o -group \) -a -atime 3

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

~]# find /etc -perm -222 
/etc/rc6.d
/etc/ssl/certs
/etc/rc4.d
/etc/redhat-release
/etc/sysconfig/network-scripts/ifup-isdn
/etc/sysconfig/network-scripts/ifdown-isdn
/etc/sysconfig/network-scripts/ifdown
/etc/sysconfig/network-scripts/ifup
/etc/sysconfig/selinux
...

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

~]# find /etc/ -type f -size +1M
/etc/selinux/targeted/modules/active/policy.kern
/etc/selinux/targeted/policy/policy.24

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

~]# find /etc/init.d -perm -113

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

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

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

~]# find /etc/ -not -perm -222 -ls |wc -l
798

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

~]# find /etc -mtime -7 -a -not \( -user root -o -user hadoop \) -ls

原创文章,作者:N22-白蚁,如若转载,请注明出处:http://www.178linux.com/46754

(0)
N22-白蚁N22-白蚁
上一篇 2016-09-19 13:48
下一篇 2016-09-19 13:48

相关推荐

  • CentOS7.3安装Jumpserver0.3.2

    CentOS7.3安装Jumpserver0.3.2 公司服务器前端增加堡垒机,选用开源的jumpserver 软件环境CentOS Linux release 7.3.1611 python 2.7.5 mysql5.7 安装git yum -y install git 克隆jumpserver # cd /opt # git clone https://…

    Linux干货 2017-07-11
  • ./././

    ./././

    Linux干货 2016-08-04
  • 文本全屏编辑器 vim

             vim在Linux中站着很重要的位置,是每一个学习Linux人员的必须掌握的技能之一,因为vim功能很强大为我们编辑文件和脚本带来了很大的方便。接下来我们来一起了解vim的功能。   文本编辑种类:     行编…

    Linux干货 2016-08-15
  • 内键命令和外部命令

    命令的基本格式 COMMAND  [OPTIONS…]  [ARGUMENTS…]        命令 (COMMAND)       OPTIONS(选项):用于启用或关闭命令的某个或某些功能      …

    2017-05-23
  • 系统排错——如何修复和保护你的系统

    作业 1、破解root口令,并为grub设置保护功能 开机启动时按e进入grub菜单,然后按a 编辑当前菜单的kernel选项,在后面追加1,s,S,single中的任意一个,然后回车,输入b键启动 进入了单用户模式,可以直接修改root密码 如何为grub设置保护功能: (1)、首先生成grub的md5密码 (2)、修改grub.conf文件 (3)、重启…

    Linux干货 2016-09-12
  • 前两周linux基础知识总结

    linux用户权限管理 软链接与硬链接 输入输出重定向 文本处理三剑客vim sed awk 包管理rpm yum 源码包编译安装

    Linux干货 2018-03-17

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-19 19:09

    写的很好。匹配ip地址的还可以在优化一下