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

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

[xw@localhost ~]$ cat /etc/passwd | grep -E "^(root|fedora|user1)\>" | cut -d: -f1,7
root:/bin/bash
fedora:/bin/bash
user1:/bin/zsh

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

[root@localhost ~]# cat /etc/rc.d/init.d/functions | grep -E -o "[^[:space:]]+\(\)"
checkpid()
__pids_var_run()
__pids_pidof()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
echo_success()
echo_failure()
echo_passed()
echo_warning()
update_boot_stage()
success()
failure()
passed()
warning()
action()
strstr()
is_ignored_file()
is_true()
is_false()
apply_sysctl()

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

[root@localhost ~]# echo "/var/log/cron" | grep -E -o "[^/]+/?$"
cron

[root@localhost ~]# echo "/var/log/cron" | grep -E -o "^(/[^/]+)+/"
/var/log/

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

[root@localhost ~]# ifconfig | grep -E -o "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>"
192
168
15
255
255
255
192
168
255
64
29
1
6
9
29
73
127
1
255
1
128
4
4
192
168
122
1
255
255
255
192
168
122
255

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

[root@localhost ~]# ifconfig | grep -E -o "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|
2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
192.168.0.15
255.255.255.0
192.168.0.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255

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

[xw@localhost ~]$ grep -E -o "[^[:space:]]+@[^[:space:]]+(com|cn|net)" mail.txt 
ewrwer@qq.com
2335466@163.com
3434@sina.com
bjbjk454@yahoo.com.cn
jsj-df2@hotmail.com
kdiwse234@263.net

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

[root@localhost ~]# find /var/ -user root -a -group mail -ls
134321240    4 drwxrwxr-x   2 root     mail         4096 Sep 16 15:51 /var/spool/mail
134905165  104 -rw-------   1 root     mail       104325 Sep 16 15:51 /var/spool/mail/root

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

[root@localhost ~]# find / \( -nouser -o -nogroup \) -type f

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

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

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

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

[root@localhost ~]# find /etc/ -size +1M -type f -exec ls -lh {} \;
-r--r--r--. 1 root root 6.7M Aug  8 16:02 /etc/udev/hwdb.bin
-rw-------. 1 root root 1.3M Aug 10 23:36 /etc/selinux/targeted/contexts/files/file_contexts.bin
-rw-r--r--. 1 root root 3.6M Aug 10 23:36 /etc/selinux/targeted/policy/policy.29
-rw-r--r--. 1 root root 1.4M Mar  6  2015 /etc/brltty/zh-tw.ctb

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

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

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

[root@localhost ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)  -type f

[root@localhost ~]# find /usr \( -not -user root -a -not -user bin -a -not -user hadoop \) -type f

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

[root@localhost ~]# find /etc/ -not -perm -222 -type f

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

[root@localhost ~]# find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \) -type f

[root@localhost ~]# find /etc/ -mtime -7 -a -not -user root -a -not -user hadoop -type f

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

赞 (0)
萝卜萝卜
上一篇 2016-10-09 09:06
下一篇 2016-10-09 09:06

相关推荐

  • N25-第18周博客作业

    1、为LNMP架构添加memcached支持,并完成对缓存效果的测试报告; LNMP的安装过程不再赘述. # yum install -y memcached # cat /etc/sysconfig/memcached  PORT=”11211″   &nb…

    2017-05-21
  • 关于文件查找和解压缩

                     文件查找和解压缩在文件系统上查找符合条件的文件,文件查找的工具有两个,locate 和find文件查找分为:          &nbs…

    系统运维 2016-08-18
  • Http请求流程

    1、http请求流程 1.连接 当我们输入这样一个请求时,首先要建立一个socket连接,因为socket是通过ip和端口建立的,所以之前还有一个DNS解析过程,把www.mycompany.com变成ip,如果url里不包含端口号,则会使用该协议的默认端口号。 DNS的过程是这样的:首先我们知道我们本地的机器上在配置网络时都会填写DNS,这样本机就会把这个…

    Linux干货 2017-02-13
  • N26-第十四周

    1、系统的INPUT和OUTPUT默认策略为DROP;[root@centos7 ~]# iptables -P INPUT DROP[root@centos7 ~]# iptables -P OUTPUT DROP1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允许访问;web服务…

    Linux干货 2017-06-20
  • 磁盘管理之MBR与GPT分区

    磁盘管理之MBR与GPT分区 2016-08-26 zanghonglei%1 $ S 磁盘管理之MBR与GPT分区 linux下的文件分为常规文件和设备文件,常规文件一定在某一个设备上被存储,不论这个设备是真实的还是虚拟的,这里的设备是linux中vfs层中的设备,也就是设备文件中的设备,vfs层的设备分为字符设备和块设备,字符设备可以类比为一个…

    Linux干货 2016-08-29
  • Linux 之LVM

    一 LVM 简介:     LVM是 Logical Volume Manager(逻辑卷管理)的简写,LVM将一个或多个硬盘的分区在逻辑上集合,相当于一个大硬盘来使用,当硬盘的空间不够使用的时候,可以继续将其它的硬盘的分区加入其中,这样可以实现磁盘空间的动态管理,相对于普通的磁盘分区有很大的灵活性。LVM的工作原理其…

    Linux干货 2016-03-01

评论列表(1条)

  • luoweiro
    luoweiro 2016-10-11 23:37

    对于find命令其实还有一些高级用法,比如时间轴相关的,这部分其实在日常工作中用到的也很多,可以再总结一番。