N22-第5周博客作业

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

grep -E "^(root|fedora|user1)\>" /etc/passwd | cut -d: -f7

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

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

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

[root@www scripts]# echo /etc/sysconfig/ | grep -E -o "[^/]+/?$"
sysconfig/
[root@www scripts]# echo /etc/sysconfig/ | grep -o "^.*/"
/etc/sysconfig/

4、找出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])\>"

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

[root@www scripts]# ifconfig | grep -o '\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}'
192.168.5.171
255.255.255.0
192.168.5.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255

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

egrep -o "[[:alnum:]]+\@[[:alnum:]]+\.[[:alnum:]]"

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

[root@www scripts]# find /var -user "root" -a -group "mail"
/var/spool/mail
/var/spool/mail/root

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

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

find / -nouser -o -nogroup 
find / \( -nouser -o -nogroup \) -atime -3

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

find /etc -perm -222 -exec ls -lh {} \;

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

find /etc/ -size +1M -type f -exec ls -lh {} \;

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

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

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

find /usr -not \( -user root -o -user bin -user hadoop \) -type f -ls

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

find /etc -not -perm 222 -type f -ls

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

find /etc -mtime -7 -not \( -user root -o -user hadoop \) -type f -ls

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

(0)
zhuckeezhuckee
上一篇 2016-12-05 17:04
下一篇 2016-12-05 17:04

相关推荐

  • 往死里苦练脚本啊啊啊啊啊啊啊~~~~~~~~~~~~~~~~

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #脚本内容 [root@centos script]# cat week9_title1.sh  #!/bin/bash #Author …

    Linux干货 2017-02-16
  • CentOS 6上的防火墙策略的保存

    两种iptables的策略保存的方法

    2018-02-27
  • week3

    一,列出当前系统上所有已经登录的用户的用户名,注意,同一个用户登录多次只显示一次即可 who | cut -d' ' -f1 | sort -u 二,取出最后登录到当前系统的用户相关信息 who | cut -d'&nb…

    Linux干货 2016-11-15
  • Nginx lnmp环境及https的实现

    一、http事务简明  request: <method> <URL> <VERSION> MHADERS <body> response: <version><status><reason phrase> <HEADERS> … <body&…

    2016-07-27
  • 认识shell

    一、认识shell 什么是shell?shell为单词外壳的意思。那么这是谁的外壳?我们知道一个系统中实际工作的是那些硬件,cpu、内存、磁盘等。我们如何调用这些硬件为我们工作?实际上,硬件是由内核kernel控制的。我们可以通过kernel控制硬件,但我们不能直接和内核kernel交流。我们需要一个外壳,这个外壳就是shell来沟通kernel。何为she…

    Linux干货 2015-09-22
  • 基于CentOS7实现LAMP(上)

    基于CentOS7实现LAMP(上)   情景模式: (1)php以模块方式运行  提供两个虚拟主机;                    &nbs…

    Linux干货 2016-08-22