马哥教育网络班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 '[email protected]' >> 1.txt
[root@localhost ~]# echo '[email protected]' >> 1.txt         
[root@localhost ~]# echo '[email protected]' >> 1.txt        
[root@localhost ~]# cat 1.txt 
[email protected]
[email protected]
[email protected]
[root@localhost ~]# cat 1.txt | grep '^[a-zA-Z0-9_-]\+@[a-zA-Z0-9_-]\+\(\.[a-zA-Z0-9_-]\+\)\+$'
[email protected]
[email protected]
[email protected]

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 16:11
下一篇 2016-08-08 16:11

相关推荐

  • 马哥教育网络班20期+第二周博客作业

    1.Linux上的文件管理类命令 2.bash命令学习总结 3.bash命令实例 4.元数据与时间戳 5.命令别名 6.练习题6~12 1.Linux上的文件管理类命令        Linux上的文件管理类命令可分为查看类、目录管理类、权…

    Linux干货 2016-06-19
  • Tomcat及Tomcat集群

    Tomcat集群实现的三种方式 配置 Tomcat1 配置环境 ip a add 192.168.88.101/24 dev ens33 yum install ntpdate -y ntpdate 172.16.0.1 安装java yum install java-1.8.0-openjdk-devel -y 安装tomcat yum install t…

    Linux干货 2017-07-08
  • 马哥教育网络班21期+第8周课程练习

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 集线器 集线器也称HUB,工作在OSI七层结构的第一层物理层,属于共享型设备,接收数据广播发出,在局域网内一般都是星型连接拓扑结构,每台工作站都连接到集线器上。 由于集线器的带宽共享特性导致网络利用效率极低,一般在大中型的网络中不会使用到集线器。 网桥 网桥(Bridge)也称桥…

    Linux干货 2016-09-01
  • Liunx课前准备

            经过与家人的沟通终于来到了北京,开始了期待已久的Linux学习之路。    今天是讲课前第一天,和上学时代一样,各位同学做了自我介绍,仿佛又置身于10年前的课堂,同学们有序的介绍着自己,今天我们坐到了一起就为了同一个梦想。之前还有很大的顾虑:学不会怎么办?出来找不到工作怎么办?……但听了大家的介绍后发现很多同学与我一样,所有的顾虑瞬间消失,希…

    2018-03-26
  • systemd

    systemd 启动流程:POST -> BIOS -> MBR bootloader -> kernel 临时根 -> 根文件系统 -> init init 能够管理、控制init进程的模块,就是init系统 能够让系统在用户预定义的级别下运行 设备管理器: sysvinit : CentOS 5 第一个广泛应用的init系统…

    Linux干货 2017-05-21
  • rsyslog日志服务

    一、知识整理: 1、日志服务rsyslogd新特点:     多线程;     基于SSL/TLS/UDP/TCP/RELP网络协议传输日志信息;     强大的过滤器,实现过滤日志信息中任何部分的内容;   &nbsp…

    Linux干货 2016-10-24

评论列表(1条)

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

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