马哥教育网络班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 
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

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

相关推荐

  • 编译安装——吐血经验,内附脚本

    程序包编译安装: 源码包:name-VERSION-release.src.rpm         rpm由源码包安装后,使用rpmbuild命令制作成二进制格式的rpm包,而后再安装        &nbsp…

    Linux干货 2016-08-24
  • 系统排错——如何修复和保护你的系统

    作业 1、破解root口令,并为grub设置保护功能 开机启动时按e进入grub菜单,然后按a 编辑当前菜单的kernel选项,在后面追加1,s,S,single中的任意一个,然后回车,输入b键启动 进入了单用户模式,可以直接修改root密码 如何为grub设置保护功能: (1)、首先生成grub的md5密码 (2)、修改grub.conf文件 (3)、重启…

    Linux干货 2016-09-12
  • 计算机基础知识(第一天)

    一、计算机的硬件组成         冯诺依曼体系结构:             CPU、存储器、输入设备、输出设备       &nbsp…

    Linux干货 2016-07-26
  • 二进制安装mysql(mariadb)

    实验环境: ~]# lsb_release -a Distributor ID: CentOSDescription: CentOS Linux release 7.4.1708 (Core)Release: 7.4.1708Codename: Core 去官方下载mariadb: https://downloads.mariadb.org/ 本人将自己的文…

    2018-01-22
  • 博客

       这是我的第一篇博客!   平时学习中,总会遇到或大或小的问题,以及一些新的感悟,在当时能够十分清晰记得,但过一些时日,便发现又忘记了。以前十分明白的东西,又变得有些模糊,甚至完全忘记。因此特别需要记录下来,方便日后的查阅或分享给其他遇到类似问题的朋友。    如果以后忘记的某些知识,这时候,翻开以往博客…

    Linux干货 2017-07-11
  • 懒人本地YUM源设置

    一、挂载本地光盘到根目录下/media。 [root@wing-PC ~]# mount -v /dev/sr0 /media/ 二、用mv 修改/etc/yum.repos.d下面的文件。 [root@wing-PC ~]# mv -v /etc/yum.repos.d/CentOS-Base.repo / CentOS-Base.repo.bak [ro…

    系统运维 2017-08-05

评论列表(1条)

  • luoweiro
    luoweiro 2016-10-11 23:37

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