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 10:13
下一篇 2016-11-21 10:13

相关推荐

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

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

    Linux干货 2016-11-07
  • LVS负载均衡wrrdpress

    项目要求:(1) lvs 调度两台 nginx+php-fpm real-server,采用 dr 模型,调度算法为 rr(2) mariadb 为 real-server 提供数据库,nfs 挂载至 2 台 real-server 提供文件服务项目环境:LVS-SERVER( CentOS 7 )DIP:172.18.99.6VIP:172.18.99.6…

    Linux干货 2017-05-16
  • 推荐-Centos常用的进程管理和资源查看工具

    一、pstree     pstree命令以树状图的方式展现进程之间的派生关系 -a:显示每个程序的完整指令,包含路径,参数或是常驻服务的标示;  -c:不使用精简标示法;  -G:使用VT100终端机的列绘图字符;  -h:列出树状图时,特别标明现在执行的程序;  -H<…

    Linux干货 2016-04-05
  • linux上RAID的工作方式

    -. RAID是什么?     磁盘阵列(Redundant Arrays of Independent Disks,RAID),是将多块廉价硬盘组合在一起当作一个更大的硬盘使用,利用可以同时对每个硬盘同时进行读写的特性提高计算机对硬盘的读写能力。我们甚至可以空出RAID中的一块或多块硬盘对整个RAID进行数据校验,提…

    Linux干货 2015-12-06
  • Linux高级磁盘管理-RAID管理

    在冯诺依曼体系机构中,输入输出要存储的外部磁盘I/O能力实在太低,尤其是企业面对高并发的访问量,在系统内部需要大量调度磁盘的上的网页文件资源,这些都会产生大量的I/O,一个磁盘的I/O能力不管如何提升毕竟是有线的,尤其是机械硬盘;同时为了保障业务的连续性,磁盘故障时必须提供冗余能力,面对这样的实际需求环境,RAID技术产生了,通过组织磁盘阵列方式提供I/O,…

    Linux干货 2016-09-06
  • LINUX下的RPM应用

    一 前言 在进入RPM的应用前,关于可执行程序的一些基本知识有必要说明一下: 1 ABI:application binary interface,这是应用程序与系统间的协议,大家都知道同一个程序在不同的操作系统平台可能会无法执行,很大程度上就是因为ABI的不同,因此,对于可执行程序,选择对应操作系统平台是第一步 2 API:application prog…

    Linux干货 2017-04-17

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-29 22:50

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