N22+张zhangzhang+第5周练习作业

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

[root@zxn ~]# cat /etc/passwd | grep -E "^root\>" | cut -d: -f7
/bin/bash

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

cat /etc/rc.d/init.d/functions | grep -E "\<[[:alpha:]]+\>\(\)"
checkpid() {daemon() {killproc() {pidfileofproc() {pidofproc() {status() {success() {failure() {passed() {warning() {action() {strstr() {

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

取基名

[root@zxn ~]# echo /etc/rc.d/init.d/functions | grep -E -o  "[^/]+/?$"
functions

取路径名:

[root@zxn ~]# echo /etc/rc.d/init.d/functions | grep -E -o  "^/.*/"
/etc/rc.d/init.d/

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

[root@zxn ~]# ifconfig | grep  -E  --color  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fec1:ddb3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c1:dd:b3  txqueuelen 1000  (Ethernet)
        RX packets 30268  bytes 4171288 (3.9 MiB)
        TX packets 4401  bytes 1321341 (1.2 MiB)
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        RX packets 41  bytes 3960 (3.8 KiB)
        TX packets 41  bytes 3960 (3.8 KiB)

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

[root@zxn ~]#  ifconfig |grep -E --color "[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[1-9]{0,1}[0-9]{1,3}"
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet 127.0.0.1  netmask 255.0.0.0

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

[root@zxn ~]# echo "zxn@ncist.edu.cn" | grep -E -o ".*@[[:alnum:]]+.(com|cn|edu.cn)$"
zxn@ncist.edu.cn

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

[root@zxn ~]# find /var/* -user root -group mail
/var/spool/mail
/var/spool/mail/root
[root@zxn ~]# ls -ld /var/spool/mail/root
-rw-------. 1 root mail 623 9月  10 18:40 /var/spool/mail/root

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

[root@zxn ~]# find  /  \( -nogroup -o -nouser \) -ls
102325563    0 -rw-rw----   1 1002     mail            0 8月 23 23:46 /var/spool/mail/user2102325565    0 -rw-rw----   1 1003     mail            0 8月 23 23:46 /var/spool/mail/user33050125    4 drwx------   5 hadoop   1001         4096 8月 24 00:54 /home/user139252847    0 drwxr-xr-x   4 hadoop   1001           37 8月 14 09:19 /home/user1/.mozilla
[root@zxn ~]# find / \( -nogroup -o -nouser \) -atime -3

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

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

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

[root@zxn ~]# find /etc -size +1M -type f -ls
2287674 6228 -r--r--r--   1 root     root      6376691 8月 14 09:26 /etc/udev/hwdb.bin
102088141 3752 -rw-r--r--   1 root     root      3839718 3月  6  2015 /etc/selinux/targeted/policy/policy.29
101494228 1336 -rw-r--r--   1 root     root      1367395 3月  6  2015 /etc/brltty/zh-tw.ctb

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

[root@zxn ~]# find /etc/init.d -perm -113 -ls
33701805    0 lrwxrwxrwx   1 root     root   11 8月 14 09:20 /etc/init.d -> rc.d/init.d

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

[root@zxn ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls
921800    4 drwx------   2 polkitd  root  4096 8月 14 09:27 /usr/share/polkit-1/rules.d
34446281   12 -rwsr-sr-x   1 abrt  abrt   11232 3月 24  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@zxn ~]# find /etc/ -not -perm -222 -type f -ls
/smartd_warning.sh
36069630    4 -rw-r--r--   1 root     root            1 10月  7  2014 /etc/at.deny
35959044    4 -rw-r--r--   1 root     root         2872 6月 10  2014 /etc/pinforc
35958973    4 -rw-r-----   1 root     root         3181 3月  6  2015 /etc/sudo-ldap.conf

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

[root@zxn ~]# find /etc -mtime -7 -not \( -user root -o -user hadoop \)

原创文章,作者:N22-北京-张zhangzhang,如若转载,请注明出处:http://www.178linux.com/45106

(0)
N22-北京-张zhangzhangN22-北京-张zhangzhang
上一篇 2016-09-15 22:21
下一篇 2016-09-15 22:21

相关推荐

  • 使用mysql-mmm实现高可用mysql读写分离

    MMM介绍:  MMM全称为Multi-Master Replication Manager for MySQL,即为主主复制管理器;根据MMM官网介绍,其工作原理类似于lvs,都是利用vip地址;但lvs只有一个组件便可以正常工作,而MMM则使用三个组件,分别是mysql-mmm、mysql-mmm-agent、mysql-mmm-monitor…

    Linux干货 2015-08-04
  • 马哥教育网络班21期+第6周课程练习

    VIM基础知识 常用模式: 编辑模式–>命令模式 输入模式 末行模式:内置的命令行接口 模式转换: 编辑模式–>输入模式 i:在光标所在处前转换为输入模式; a:在光标所在后面转入输入模式; o:在当前光标所在行的下方打开一个新行,并转为输入模式; I:在当前光标所在行的行首输入; A:在当前光标所在行的行尾输入; O:在当前光标所在行的上方…

    Linux干货 2016-08-15
  • Linux系统的文件管理命令及bash的相关工作特性

    熟悉Linux系统的文件管理命令,了解bash的工作特性,加强练习并掌握其内容。

    2017-09-30
  • 第四周博客作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 ~]# cp -r /etc/skel /home/tuser1 ]# chmod -R 700 /home/tuser1/ 2、编辑/etc/group文件,添加组hadoop ~]# echo "hadoop:…

    Linux干货 2016-12-14
  • TCP/IP五层模型

    1、简述osi七层模型和TCP/IP五层模型 网络的七层模型是由OSI和CITT一起制定的开放系统互连参考模型: TCP/IP 五层模型可以分为:应用层,传输层,网络层,数据链路层,物理层。 2、简述ip route家族命令 语法:ip [ OPTIONS ] OBJECT { COMMAND | help } OBJECT={link ,addr,rout…

    2018-01-05
  • bash的特性总结

    什么是bash:       shell作为用户与计算机内核交互的接口,是用户与计算机沟通的桥梁,而bash(borne again shell)是众多shell里面最为流行一种,bash作为众多shell里面的一种有着众多的特性,掌握bash的众多特性将会是我们今后学习linux必经之路。&nbs…

    Linux干货 2015-10-27