马哥教育网络班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)
上一篇 2016-08-08 16:11
下一篇 2016-08-08 16:11

相关推荐

  • linux文件系统

    linux的文件系统:             根文件系统为rootfs(root file system)           &nbsp…

    Linux干货 2015-12-19
  • shell位置变量解析

    什么是位置变量 在脚本代码中调用通过命令行传递给脚本的参数。 有哪些位置变量 $1,$2,…: 对应第1、第2等参数,shift [n]换位置 $0:命令本身 $*:传递给脚本的所有参数,全部参数合为一个字符串 $@:传递给脚本的所有参数,每个参数为独立字符串$#:传递给脚本的参数的个数    &nbsp…

    Linux干货 2016-08-15
  • 打造自己小小的RPM包

    关于源码RPM包的安装于制作 什么是RPM与SRPM? 1     RPM: 1     SRPM: 2     SRPM的安装 2 一 .利用rpmbuild默认安装SRPM档案 2 二.配置路径与需要的软件功能模块 3  &n…

    Linux干货 2016-08-24
  • 马哥教育网络班22期第1周课程作业

    一、基础中的基础————–计算机的组成部分         计算机组成分为硬件系统与软件系统         硬件包括五个部分     1.控制器:控制器 I/O 存储器 &nbs…

    Linux干货 2016-08-15
  • apache工作模式及虚拟主机的配置

    apache的工作模式 MPM 名词解释MPM   Multipath Process Module 多道处理模块。Linux中常使用prefork worker event三种MPM 即apache常用的三种工作模式。 prefork prefork为多进程模型,每个进程响应一个请求。其工作过程简单说来就是一个主进程:负责生成n个 子进程(子进程…

    Linux干货 2016-07-02
  • haproxy 监控配置

    方法一:在defaults段增加如下配置: stats refresh 30s #统计页面自动刷新时间stats uri /stats #统计页面urlstats realm baison-test-Haproxy #统计页面密码框上提示文本stats auth admin:admin123 #统计页面用户名和密码设置stats hide-version #…

    Linux干货 2018-03-19

评论列表(1条)

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

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