马哥教育网络班21期+第5周作业

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行(以/boot/grub2/grub.cfg代替);

[root@localhost ~]# grep '^[[:space:]]\+' /boot/grub2/grub.cfg 
  load_env
   set default="${next_entry}"
   set next_entry=
...内容略

2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行(以/etc/rc.d/init.d/functions代替 );

[root@localhost ~]# cat /etc/rc.d/init.d/functions | grep '^#[[:space:]]\+[^[:space:]]\+' 
# -*-Shell-script-*-
# functions     This file contains functions to be used by most or all
#               shell scripts in the /etc/init.d directory.
# Make sure umask is sane
# Set up a default search path.
# Get a sane screen width

3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

[root@localhost ~]# netstat -tan | grep 'LISTEN[[:space:]]*'
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN

4、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

[root@localhost ~]# useradd bash && useradd testbash && useradd basher && useradd -d /sbin/nologin nologin
[root@localhost ~]# grep '^\([^:]\+\):.*/\1$' /etc/passwd                                   sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
123:x:1111:1111::/123:/123
bash:x:1129:1129::/home/bash:/bin/bash
nologin:x:1130:1130::/home/nologin:/sbin/nologin

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

[root@localhost ~]# cat /etc/passwd |  grep '^\(root\|fedora\|user1\):' | cut -d: -f1,7
root:/bin/bash
user1:/bin/bash

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

[root@localhost ~]# cat  /etc/rc.d/init.d/functions | grep '^[[:alpha:]]\+()'
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {

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

[root@localhost ~]# echo '/etc/ppp' | grep -o '^.*[^/]' | grep -o '/[^/]\+/\?$'   
/ppp

7.2、扩展:取出其路径名

[root@localhost ~]# echo '/etc/ppp' | grep -o '^.*[^/]' | grep -o '^.*/'     
/etc/

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

[root@localhost ~]# ifconfig | egrep   '\<([1-9][1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>'
        inet 1.1.1.117  netmask 255.255.255.0  broadcast 1.1.1.255
        RX packets 1970  bytes 223843 (218.5 KiB)
        TX packets 1264  bytes 225028 (219.7 KiB)
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        RX packets 4  bytes 340 (340.0 B)
        TX packets 4  bytes 340 (340.0 B)
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

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

[root@localhost ~]# ifconfig | grep -o  --color '\(\([0-9]\|[1-9][0-9]\|1[0-9]\{2\}\|2[0-4][0-9]\|25[0-5]\)\.\)\{3\}\([0-9]\|[1-9][0-9]\|1[0-9]\{2\}\|2[0-4][0-9]\|25[0-5]\)'
1.1.1.117
255.255.255.0
1.1.1.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255

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

[root@localhost ~]# echo '372564854@qq.com' >> 1.txt
[root@localhost ~]# echo '12345678@qq.com' >> 1.txt         
[root@localhost ~]# echo 'lich9978@qq.com' >> 1.txt        
[root@localhost ~]# cat 1.txt 
372564854@qq.com
12345678@qq.com
lich9978@qq.com
[root@localhost ~]# cat 1.txt | grep '^[a-zA-Z0-9_-]\+@[a-zA-Z0-9_-]\+\(\.[a-zA-Z0-9_-]\+\)\+$'
372564854@qq.com
12345678@qq.com
lich9978@qq.com

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

[root@localhost ~]# find /var -user root -group mail
/var/spool/mail

12、查找当前系统上没有属主或属组的文件;

[root@localhost ~]# find / \( -nouser -o -nogroup \) -a -atime -3
find: ‘/proc/3745/task/3745/fd/6’: 没有那个文件或目录
find: ‘/proc/3745/task/3745/fdinfo/6’: 没有那个文件或目录
...内容略
/home/nologin/.mozilla/extensions
/home/nologin/.mozilla/plugins
[root@localhost ~]#

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

[root@localhost etc]# find /etc -perm -g+w,u+w,o+w
/etc/mtab
/etc/pki/java/cacerts
/etc/pki/tls/cert.pem
...略
/etc/httpd/run
/etc/1.txt

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

[root@localhost etc]# find /etc -size +1M -type f
/etc/udev/hwdb.bin
/etc/selinux/targeted/policy/policy.29
/etc/brltty/zh-tw.ctb

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

[root@localhost etc]# find /etc/init.d -perm -g+x,o+wx,u+x
/etc/init.d

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

[root@localhost etc]# find /usr -not \( -user root -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@localhost etc]# find /etc/ ! -perm -444                                       
/etc/crypttab
/etc/pki/CA/private
...内容略
/etc/libvirt/nwfilter
/etc/gssproxy/gssproxy.conf

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

[root@localhost etc]# chown basher 1.txt
[root@localhost etc]# ll 1.txt 
-rw-rw-rw-. 1 basher root 0 8月   7 21:11 1.txt
[root@localhost etc]# find /etc ! -user root ! -user hadoop  -ctime -7           
/etc/1.txt

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

(0)
lichenhanlichenhan
上一篇 2016-08-08
下一篇 2016-08-08

相关推荐

  • 网络管理

    说起网络,大家都不陌生,因为大家天天上网嘛,连路边老大爷都会聊微信了,但是我们所了解的网络只是茫茫网络大海中的一叶扁舟,网络的范围其实有很大,里面涉及的东西也非常多,现在让小编带你一点一点去了解它吧,相信大家看了之后,会有不一样的体会呢! 1、 什么是网络? 网络是由节点和连线构成,表示诸多对象及其相互联系。在数学上,网络是一种图,一般认为专指加权图。网络除…

    2017-09-02
  • Linux常见文件管理命令

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。2、bash的工作特性之命令执行状态返回值和命令行展开所涉及的内容及其示例演示。3、请使用命令行展开功能来完成以下练习:(1)、创建/tmp目录下的:a_c, a_d, b_c, b_d(2)、创建/tmp/mylinux目录下的:mylinux/├── bin├── boot│  …

    2018-02-26
  • 第一周

    1、描述计算机的组成与功能 计算器是由运算器,控制器,存储器,输入设备和输出设备五大部件组成;每一部件分别按要求执行特定的功能,具体功能如下: (1)运算器:完成各种算术运算和逻辑运算的装置,能进行加、减、乘、除等数学运算,也能作比较、判断、查找、逻辑运算等。 (2)控制器:控制器是计算机机指挥和控制其它各部分工作的中心,其工作过程和人的大脑指挥和控制人的各…

    Linux干货 2017-01-02
  • 日志分析工具Awstats实战之Nginx篇-分析结果静态化

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1316979 前言: Awstats 是在 SourceForge 上发展很快的一个基原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处…

    Linux干货 2016-08-15
  • shell脚本之批量添加用户

        没错,这是一个简单的脚本,不写不知道,写了才发现自己多垃圾。     我是一名普通的公司网络管理,接触linux不长,一直理想都是和马哥学习linux,可惜因为拖家带口的原因,没办法交学费和马哥学习,心里小小遗憾吧。每天看着马哥的文章以及百度搜索的视频文章学习,感觉自己学…

    Linux干货 2016-07-07
  • 马哥教育网络班20期-第四周课程作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。       cp -r /etc/skel /home/tuser1 | chmod -R g…

    Linux干货 2016-06-29

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-08 17:00

    写的很好,排版也很棒,加油