马哥教育网络班22期第5周课程作业

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

cat /etc/passwd | grep ^root | cut -d: -f7

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

cat /etc/rc.d/init.d/functions |grep -e "\<[[:alpha:]]*\>()"

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

    扩展:取出其路径名

echo "/etc/fstab" | grep -o "\<[[:alpha:]]*$"
echo "/etc/fstab" | grep -o "[/].*[/]"

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

[root@localhost ~]#  ifconfig | egrep -o "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])"

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

ifconfig | egrep -o "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\.){3}([0-9]|[1-9][
0-9]|1[0-9][0-9]|2[0-5][0-5])"

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

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

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

[root@localhost ~]# find /var -user root -group mail -ls
67150324    0 drwxrwxr-x   2 root     mail           31 9月  9 18:32 /var/spool/mail

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

[root@localhost ~]#  find / -nouser -o -nogroup
find: ‘/proc/14232/task/14232/fd/6’: 没有那个文件或目录
find: ‘/proc/14232/task/14232/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/14232/fd/6’: 没有那个文件或目录
find: ‘/proc/14232/fdinfo/6’: 没有那个文件或目录
/root/duqiu.sh

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

[root@localhost ~]#  find / -nouser -o -nogroup -a -atime -3
find: ‘/proc/14246/task/14246/fd/6’: 没有那个文件或目录
find: ‘/proc/14246/task/14246/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/14246/fd/6’: 没有那个文件或目录
find: ‘/proc/14246/fdinfo/6’: 没有那个文件或目录
/root/duqiu.sh

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

 find /etc -perm  -111 -ls

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

[root@localhost ~]# find /etc -size +1M -type f -ls
34321825 6824 -r--r--r--   1 root     root      6984832 9月  9 16:05 /etc/udev/hwdb.bin
67923043 3772 -rw-r--r--   1 root     root      3858924 11月 21  2015 /etc/selinux/targeted

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

 find /etc/init.d/  -perm -113 -ls

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

[root@localhost ~]# find /usr -not -user root -a -not -user bin -a -not -user hadoop -ls
67532253    0 drwx------   2 polkitd  root            6 6月 10  2014 /usr/share/polkit-1/ru
les.d

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

 find /etc/ -not -perm -777 ^C

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

[root@localhost ~]# find /etc -atime -7 -a -not -user root -o -not -user hadoop -ls
101092311    0 drwx------   2 polkitd  root           63 9月  9 15:50 /etc/polkit-1/rules.

原创文章,作者:杜邱,如若转载,请注明出处:https://www.178linux.com/46064

赞 (0)
杜邱杜邱
上一篇 2016-12-05 17:03
下一篇 2016-12-05 17:03

相关推荐

  • N26 第七周作业

    1、创建一个10G分区,并格式为ext4文件系统;(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; [root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in mem…

    Linux干货 2017-02-07
  • 第一周作业-01

    计算机组成    硬件:主要由5大部件组成,CPU包含运算器和控制器两大部件        CPU:运算器、控制器、寄存器、缓存        存储器:内存,RAM(Random Access Memory)    , Memory只支持平…

    Linux干货 2016-09-10
  • Linux网络属性管理(二)

    Linux网络属性(二) Linux 网络属性管理(二) ip命令 ip – show / manipulate routing, devices, policy routing and tunnels ip [ OPTIONS …

    Linux干货 2016-07-07
  • linux中nmcli命令使用及网络配置

      Red Hat Enterprise Linux 7 与 CentOS 7 中默认的网络服务由 NetworkManager 提供,这是动态控制及配置网络的守护进程,它用于保持当前网络设备及连接处于工作状态,同时也支持传统的 ifcfg 类型的配置文件。  NetworkManager 可以用于以下类型的连接:Ethernet,VLA…

    Linux干货 2016-09-10
  • 系统启动这块的一些实验及基本内容–下

    下面我来讲下grub,grub在编辑的时候可以进入一种模式就是单用户模式,就是当grub.conf文件未写入密码时,普通用户将直接忽略系统密码进入系统,所以这可以称为一个捷径,也可以成为一个漏洞,当然linux的前辈们不可能连这个都想不到,他们也有自己的办法,这就是我们grub的两层加密机制,在选定登陆界面之前可以设置一次,启动内核时也可以设置一次,密码也可…

    Linux干货 2016-09-13