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

相关推荐

  • Linux用户及组的管理相关知识

    Linux用户及组的管理相关知识 1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 ~]# who | cut -d " " -f1 | sort -u 2、取出最后登录到当前系统的用户的相关信息。 ~]# last -x | head -1 3、取出当前系统上被用户当作其默认shell的最多的那…

    Linux干货 2016-10-05
  • 磁盘管理与文件系统

      关于磁盘与文件系统大致思路:要想对磁盘进行充分利用,必须要对磁盘进行分区,第二步就是要对分区进行高级格式化,也就是在分区上创建文件系统,在此过程中可以对磁盘的各种属性进行自定义。打个比方来说,创建磁盘分区好比刚买来一个毛坯房,还未装修,还不适宜人居住,那么创建文件系统就好比在光秃秃的毛坯房上进行了装修,这样才更适于人居住使用。 要想搞懂磁盘,首…

    Linux干货 2016-08-30
  • 7月21号:CentOS6.8(及7)基础配置项+Linux入门(1)

    7月21号,马哥第二天,主要内容有三个部分:一、基本命令复习二、CentOS6.8(及7)基础配置项;三、linux入门(1) 一、基本命令复习    ls         查看文件内容  l查看文件详细信息  -a显示包含隐藏文…

    Linux干货 2016-08-05
  • 常见的文本处理工具及正则表达式的相关知识

    1.cat命令使用详解 cat [option]… [file]… -A equivalent=vET -b 非空行编号 -E 行为显示$ -n 显示所有行的行号 -s 行号并压缩连续空行为一行 -T 显示tab为^M 实例:显示a文件的行号及所有控制符 2.(1)head使用详解 head -n x 显示前x行 head -c x …

    Linux干货 2016-08-07
  • LAMP+NFS实现双web服务负载均衡

        一、实验拓扑          二、系统环境      1、主机A、主机B、主机C:CentOS 6.5        测试PC:         Windows 7 旗舰…

    Linux干货 2015-07-06

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-29 22:50

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