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

相关推荐

  • Linux概述

    计算机组成概述 计算机组成原理 如上图计算机的组成结构,CPU运行速度远远高于内存,而内存运行速度又远远高于I/O;由于三者运行速度巨大差异,如果系统仅运行一个任务(单任务系统),那么将有大量的CPU空闲时间等待缓慢的I/O及内存的读取。为提高CPU的使用效率,于是便产生了多任务系统系统的需求。 多任务系统 多任务实现的基础,我们知道计算机处理任务主要靠CP…

    Linux干货 2016-12-02
  • HAproxy reload config file with uninterrupt session

    HAProxy is a high performance load balancer. It is very light-weight, and free, making it a great option if you are in the market for a load balancer and need to keep your cos…

    Linux干货 2015-04-03
  • 马哥教育网络20期+第四周课程练习

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

    Linux干货 2016-07-04
  • 8 文本查看、处理与统计分析

    文本查看 cat cat [OPTION]… [FILE]… 该命令用于正向查看文本文件,但不可分页,一次性显示完成 参数说明 参数 说明 -E 显示行结束符$ -n 对显示出的每一行进行编号 -A 显示所有控制符 -b 非空行编号 -s 压缩连续的空行成一行 -T 显示tab为^I 示例  tac tac […

    Linux干货 2016-08-10
  • 文本查找之find组合拳

    find命令不仅能帮助我们在数目众多的文件中快速找到满足条件的文本,我们还能通过find处理动作对查找到的文件进行进一步的处理。 一、find的特点:               遍历查找,因此查找速度略慢   &nbs…

    Linux干货 2016-08-15
  • 高可用keepalived结合haproxy代理WordPress(动静分离)

    (1)A  B两台服务器做keepalived高可用,同时作为haproxy动静分离后端代理。         (keepalived时主备模型,haproxy轮询调度) (2)C 服务器搭建apache作为动态资源服务器 (3)D 服务器搭建nginx作为静态资源服务器 (4)VIP:172.18.0.42…

    2017-05-20