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

相关推荐

  • Shell 变量类型及用法

    一、      什么是变量          变量源于数学,在计算机语言中能储存计算机结果或能表示值的抽象概念,变量可以由变量名访问,在指令语言中,变量通常是可变的。Linux是一个多用户的操作系统。每个用户登录系统后,都会有一个…

    Linux干货 2016-08-12
  • sed命令解析

    处理文件的工具sed Stream EDitor, 行编辑器 一次只读一行,只处理一行,不对源文件做处理,至输出到屏幕上模式空间 sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space), 接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往…

    Linux干货 2016-08-11
  • 压缩、解压缩及归档工具

    压缩、解压缩及归档工具 一、杂项知识整理 1、find -iname 忽略大小写;     -inum 查找指定inode号的文件;  find 在有条件判断的时候,如果不加括号,最后的命令会被当成以为第二个条件之后的:例 [root@localhost shelltest]# find&…

    Linux干货 2016-08-18
  • 笔记–8.2–用户管理,权限管理

    ·硬链接,软链接区别 大小 链接数 设备,分区 类型 硬连接 一样大,显示的是本身的大小 会增加 不能跨分区 是一个文件,相同inode号,忘了位置可通过inode号找到源文件 软链接 不一样大,链接文件大小是路径的大小 不会增加 可以跨分区,跨设备 两个文件,不同inode号,像发小广告,忘了源连接,文件就找不到了 软链接格式:ln -s +绝对路径或相对…

    Linux干货 2016-08-05
  • Ip 地址 及 网络配置

    Ip 地址 及 网络配置 IP地址  它们可唯一标识 IP 网络中的每台设备  每台主机(计算机、网络设备、外围设备)必须具有唯 一的地址 IP地址由两部分组成:       网络ID:  标识网络  每个网段分配一个网络ID       主机 ID:  标识单个主…

    Linux干货 2016-09-05
  • HAProxy初探及简单案例_Net21_第二周

    前言 随着互联网业务的迅猛发展,大型电商平台和门户网站对系统的可用性和可靠性的要求越来越高,高可用集群、负载均衡集群成为一种热门的系统架构解决方案。在众多的负载均衡解决方案中,有基于硬件的负载均衡设备,例如F5、Big-IP等,也有基于软件的负载均衡产品,如LVS、Nginx以及本文介绍的HAProxy等。在软件的负载均衡产品中,又分为两种实现方式,分别是基…

    Linux干货 2016-07-22

评论列表(1条)

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

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