N22- 第五周

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

[root@localhost Packages]# grep -E "^(root|fedora|user1\>)" /etc/passwd | cut -d: -f 1,7
root:/bin/bash
fedora:/vin/zsh
user1:/bin/bash

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

[root@localhost Packages]# grep -E "\<[a-z]*\>\(\)" /etc/rc.d/init.d/functions 
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {

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

[root@localhost ~]# echo /etc/sysconfig/network-scripts/ | grep -E -o '^/.*[^/]' | grep -E -o '[^/]+/?$'
network-scripts

    扩展:取出其路径名

[root@localhost ~]# echo /etc/sysconfig/network-scripts/ | grep -E -o '^/.*[^/]' | grep -E -o '^/.*/'
/etc/sysconfig/


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

[root@localhost ~]# ifconfig | grep -E -o '\([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]\)'
167
77
73
41
63
150
192
168

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

[root@localhost ~]# ifconfig | grep -E -o "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
192.168.8.233
192.168.8.255

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

[root@localhost scripts]# grep -E -o '[^[:space:]]+@[^[:space:]]+\.com'  mail.txt 
123434@163.com
steph_fase@163.com
sdf2121_fsdf@sohu.com

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

[root@localhost tmp]# find /var -user root -group mail -ls 
201327614    0 drwxrwxr-x   2 root     mail           67 Nov 15 13:24 /var/spool/mail

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

[root@localhost tmp]# find / \( -nouser -o -nogroup \) -ls
 46767   35 -rw-rw-r--   1 502      502         35380 Jul  4  2014 /mnt/dvd/Packages/zziplib-utils-0.13.62-5.el7.x86_64.rpm
 46771  137 -rw-rw-r--   1 502      502        140092 Jul  4  2014 /mnt/dvd/Packages/zziplib-devel-0.13.62-5.el7.x86_64.rpm
 46776  137 -rw-rw-r--   1 502      502        140088 Jul  4  2014 /mnt/dvd/Packages/zziplib-devel-0.13.62-5.el7.i686.rpm
 46784   82 -rw-rw-r--   1 502      502         83176 Jul  4  2014 /mnt/dvd/Packages/zziplib-0.13.62-5.el7.x86_64.rpm
 46788   82 -rw-rw-r--   1 502      502         83640 Jul  4  2014 /mnt/dvd/Packages/zziplib-0.13.62-5.el7.i686.rpm

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

[root@localhost tmp]# find / \( -nouser -o -nogroup \) -atime -3 -ls

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

[root@localhost tmp]# find /etc -perm -222 -type f -ls

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

[root@localhost tmp]# find /etc/ -size +1M -type f -ls 
2155134 6228 -r--r--r--   1 root     root      6376691 Aug 25 10:12 /etc/udev/hwdb.bin
137800582 1364 -rw-r--r--   1 root     root      1395438 Jun 10  2014 /etc/gconf/schemas/ekiga.schemas

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

[root@localhost init.d]# find /etc/init.d/ -perm -113 -ls 
  8316    0 ---x--x-wx   1 root     root            0 Nov 17 11:13 /etc/init.d/a

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

[root@localhost init.d]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls  
1431384    4 drwx------   2 polkitd  root         4096 Aug 25 10:18 /usr/share/polkit-1/rules.d

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

[root@localhost init.d]# find /etc/ -perm -111 -type f -ls

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

[root@localhost init.d]# find /etc -mtime -7 -a -not \( -user root -o -user hadoop \) -ls





原创文章,作者:N22-成都-stephen,如若转载,请注明出处:http://www.178linux.com/59550

(0)
N22-成都-stephenN22-成都-stephen
上一篇 2016-11-21
下一篇 2016-11-21

相关推荐

  • ​Bash2

    字串比较时变量最好使用"" 这样就不会报错了,只是退出码不为0 组合条件:     与:[ condition1 -a condition2 ]或condition1 && condition2     或:[ condition1 -o co…

    Linux干货 2016-09-25
  • Linux程序包管理

    Linux程序包管理 RPM包基础 RPM YUM 编译安装 概述 Linux上的程序包管理,是我们的必备技能,本文将从三个视角:rpm、yum、源码编译来浅析Linux的程序包管理。首先,我们来看下本文的主要内容: – 程序包的命名- RPM: 程序包管理器    安装、卸载、升级、查询…

    Linux干货 2016-08-29
  • 7月19号:计算机基础+在VMware12中安装CentOS6.8

        16号从正下暴雨的武汉来到帝都参加马哥培训班,从清河公寓亮哥开始,到宿舍另外五位室友,渐渐认识更多人,还算适应额不错。但走在北京的马路上,多少还是有些陌生,不过就如宿舍一样,来的时候脏兮兮,经过一番打扫后,干净了不少,我也会很快习惯在这边的生活,精力全放在linux上!   &nb…

    Linux干货 2016-08-05
  • 优云软件:双态运维下,老司机是怎么玩CMDB的?

    行业内有个科技公司,CMDB前后建设12年,重构了N次,一言不合就重构,我深深的被这种屡拆屡战,初心不改精神所折服。我真心想问下做CMDB的兄弟,各位是怎么熬过来的?请不要回避,其实我们都曾被这样虐过! 近几年我司承建国内很多传统行业的CMDB项目,坦白的说,随着互联网+热潮的冲击,因很多传统企业也慢慢的在转变业务,把很多传统型的业务互联网化,或者开辟新型业…

    2016-08-05
  • Mysql备份II

    Mysql备份II V.II.I单台或共用机器,数据量和访问量小50G< 1 Mysqldump(全导出,导库,导表) 锁表 如果这时有些入会锁住或者超时 2 至少停止写入 防止innodb配置还没刷到磁盘里 先flash tables /usr/local/mysql/bin/mysqladmin -S /tmp/mysql.so…

    Linux干货 2016-06-09
  • N22-第九周作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash # declare -i log_user declare -i notlog_user while read&n…

    Linux干货 2016-10-24

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-29 22:50

    作业完成的还算不错,有拓展和挑战,如果有自己对grep的基础总结就会更好了,加油。