N25_第五周作业

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

[root@EASTED ~]# grep -E "(root|fedora|user1)" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
fedora:x:1013:1013::/home/fedora:/bin/bash
user1:x:1014:1014::/home/user1:/bin/bash

[root@EASTED ~]# grep -E "(root|fedora|user1)" /etc/passwd|cut -d: -f7
/bin/bash
/sbin/nologin
/bin/bash
/bin/bash

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

[root@EASTED ~]# grep  -E  -o  "[_[:alnum:]]+\(\)"  /etc/rc.d/init.d/functions
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@aio2 ~]# echo /etc/sysconfig/network-scripts/ifcfg-eno1 | grep "[^\/]\+\/\?$"
/etc/sysconfig/network-scripts/ifcfg-eno1

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

[root@EASTED ~]# ifconfig | grep  -E  -o  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
192
168
7
13
255
255
255
192
168
7
255
64
29
22
6
8
2
3
73
127
1
255
1
128
22
1
7
22
1
7
192
168
122
1
255
255
255
192
168
122
255
52
54
17
54

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

[root@aio2 ~]#  ip addr list | grep -E -o "\<((1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\>"
127.0.0.1
10.10.139.12

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

[root@aio2 ~]# grep -E "[^[:space:]].*@[^[:space:]].*" mail

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

[root@EASTED ~]# find /var -user root -a -group mail -ls 
100664302    4 drwxrwxr-x   2 root     mail         4096 1月  2 23:13 /var/spool/mail
103173137    4 -rw-------   1 root     mail          661 1月  2 12:37 /var/spool/mail/root

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

[root@EASTED ~]# find / -nouser -a -nogroup -a -atime -3
find: ‘/proc/26189’: 没有那个文件或目录
find: ‘/proc/26379’: 没有那个文件或目录
find: ‘/proc/26380/task/26380/fd/6’: 没有那个文件或目录
find: ‘/proc/26380/task/26380/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/26380/fd/6’: 没有那个文件或目录
find: ‘/proc/26380/fdinfo/6’: 没有那个文件或目录
find: ‘/run/user/1000/gvfs’: 权限不够
/home/bash
/home/bash/.mozilla
/home/bash/.mozilla/extensions
/home/bash/.mozilla/plugins
/home/bash/.bash_logout
/home/bash/.bash_profile
/home/bash/.bashrc
/home/testbash
/home/testbash/.mozilla
/home/testbash/.mozilla/extensions
/home/testbash/.mozilla/plugins
/home/testbash/.bash_logout
/home/testbash/.bash_profile
/home/testbash/.bashrc
/home/basher
/home/basher/.mozilla
/home/basher/.mozilla/extensions
/home/basher/.mozilla/plugins
/home/basher/.bash_logout
/home/basher/.bash_profile
/home/basher/.bashrc
/home/nologin
/home/nologin/.mozilla
/home/nologin/.mozilla/extensions
/home/nologin/.mozilla/plugins
/home/nologin/.bash_logout
/home/nologin/.bash_profile
/home/nologin/.bashrc

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

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

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

[root@EASTED ~]# find /etc -size +1M -type f -exec ls -lh {} \;
-rw-r--r--. 1 root root 3.7M 11月 21 2015 /etc/selinux/targeted/policy/policy.29
-r--r--r--. 1 root root 6.7M 8月  31 22:36 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 1.4M 3月   6 2015 /etc/brltty/zh-tw.ctb

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

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

12、查找/usr目录下不属于root、bin或hadoop的文件;[root@EASTED ~]# find /usr -not ( -user

root -o -user bin \) -ls
68670714    4 drwx------   2 polkitd  root         4096 8月 31 22:24 /usr/share/polkit-1/rules.d
34502454   16 -rwsr-sr-x   1 abrt     abrt        15336 12月  1  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

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

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

[root@EASTED ~]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop -ls

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

(0)
LYFLYF
上一篇 2017-01-10 22:33
下一篇 2017-01-10 23:41

相关推荐

  • 马哥教育网络班21期-第五周课程练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@localhost ~]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符…

    Linux干货 2016-08-08
  • RHCE系列之磁盘加密—-LUKS加密

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1436460        LUKS (Linux Unified Key Setup)为 Linux 硬盘…

    Linux干货 2016-08-15
  • 分区”魔术师”的磁盘管理

    设备文件 I/O Ports: I/O设备地址 一切皆文件: open(), read(), write(), close() 设备类型: 块设备: block,存取单位“块”,磁盘 字符设备: char,存取单位“字符”,键盘 设备文件:关联至一个设备驱动程序,进而能够跟与之对应 硬件设备进行通信 设备号码: 主设备号: major number, 标识设…

    Linux干货 2016-08-29
  • N23-第二周

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。     显示指定目录下的文件列表:ls     文件查看类命令:cat,tac,head,tail,more,less     复制命令:cp,install &…

    Linux干货 2016-09-26
  • linux下NTP服务

    linnux NTP

    2017-10-18
  • Linux网络属性管理

    Linux网络属性管理 linux的网络配置方法有多种,而且随发行版及版本而略微不同。我目前的测试环境为CentOS6和CentOS7。 常用的网络配置命令或方法有:ifconfig,route,netstat,ip,ss,nmcli,配置文件。 首先:命令方法介绍 一、命令简介 ifconfig:是个比较传统的命令,可以配置网络接口的启用及关闭,IP地址等…

    系统运维 2016-05-29

评论列表(1条)

  • 马哥教育
    马哥教育 2017-02-17 10:25

    写的很好,排版也很漂亮,继续加油