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

相关推荐

  • diy自己的linux

    准备一台liunx的机器,我用的是liunx虚拟机 单独加载一块硬盘,我加载了一块20G的硬盘,然后用fdisk /dev/sdb进行分区,sdb1用来作为将来系统的/boot分区,所有100M就可以了,sdb2用来作为将来系统的/分区,我给了10G。然后将两个分区格式化为ext4系统。 mkdir /mnt/boot mkdir /mnt/sdc2 mou…

    Linux干货 2016-09-14
  • 以水浒为例解释文件权限

    关于文件权限的内容学起来比较绕,稍不注意就会把自己绕晕,这时候不如找一个例子来记忆,这样记起来比较容易而且还会记忆深刻,接下来就以水浒为例解释下关于文件权限方面的内容 桃园三结义,兄弟三人组成一个组,选刘备当大哥,兄弟三人都在这个组里 兄弟三人还是居无定所的,要给刘关张兄弟三人造个房子,给兄弟三人一个容身之所,而且给兄弟三人一人一个房间   但建好…

    2017-07-30
  • Linux磁盘管理进阶

    Linux磁盘管理进阶 dd命令 SWAP与移动介质 磁盘配额 RAID dd命令 dd – convert and copy a file Copy a file, converting and formatting according&…

    Linux干货 2016-09-05
  • Linux用户和组的相关命令(二、组的相关命令)

    用户和组之间息息相关。创建用户时 ,Linux系统会默认生成一个与用户名相同的组,这个组是用户的私有组,也是用户的主组。对用户来说,主组有且只有一个,但是可以有零个或多个附加组。可以在组内设置组管理员来管理组内的用户列表,组管理员可以删除用户列表内的组员。组管理员不唯一,可以有零个或多个。 关于组及其属性和组密码及其属性的有关信息保存在/etc/group和…

    2017-07-22
  • nginx_http_proxy,upstream,stream模块简析

    一. ngx_http_proxy_module模块:         模块功能: 为后端httpd服务做反向代理, 并且与Httpd 之间使用http进行通信       1、proxy_pass URL;  &nbs…

    Linux干货 2016-10-29
  • 马哥教育网络班21期+第7周课程练习

    1、创建一个10G分区,并格式为ext4文件系统;     fdisk /dev/sdb    n p 1 +10G w (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl…

    Linux干货 2016-08-22

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-29 22:50

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