第五周作业

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

[root@centos6 ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf  
        root (hd0,0)
        kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-642.el6.x86_64.img

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

[root@centos6 ~]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg's bcheckrc.
# Check SELinux status
# Print a text banner.
# Only read this once.
# Initialize hardware
# Set default affinity
# Load other user-defined modules
...

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

[root@centos6 ~]# netstat -tan|grep "LISTEN[[:space:]]*$"
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      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN

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

[root@centos6 ~]# useradd bash
[root@centos6 ~]# useradd testbash
[root@centos6 ~]# useradd basher
[root@centos6 ~]# useradd -s /sbin/nologin nologin
[root@centos6 ~]# grep "^\([[:alpha:]]\+\>\):.*/\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
bash:x:501:501::/home/bash:/bin/bash
nologin:x:504:504::/home/nologin:/sbin/nologin

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

[root@centos7 ~]# grep -E "^\<(root|fedora|user1)\>" /etc/passwd|cut -d: -f1,7
root:/bin/bash
fedora:/bin/bash
user1:/bin/bash

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

[root@centos7 ~]# grep "[[:alpha:]]\+()" /etc/rc.d/init.d/functions 
checkpid() {
__pids_var_run() {
__pids_pidof() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
echo_success() {
...

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

[root@centos7 ~]# basename $(echo "/etc/rc.d/init.d/functions")
functions

扩展:取出其路径名

[root@centos7 ~]# dirname $(echo "/etc/rc.d/init.d/functions")
/etc/rc.d/init.d

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

[root@centos7 ~]# ifconfig |grep -Eo "\<[2-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-5][0-4]\>"
192
168
11
192
168
64
29
27
48
6
4
4
73
127
128

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

[root@centos7 ~]# ifconfig|grep -Eo "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\.\
> ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\.\
> ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\.\
> ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>"
192.168.0.11
255.255.255.0
192.168.0.255
127.0.0.1
255.0.0.0

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

[root@centos7 ~]# grep "[[:alnum:]]\+@[[:alnum:]]\+" email.txt  
magedu@163.com
magedu@qq.com

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

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

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

[root@centos7 ~]# find / -type f -nouser -nogroup
find: ‘/proc/7703/task/7703/fdinfo/6’: No such file or directory
find: ‘/proc/7703/fdinfo/6’: No such file or directory
/home/archlinux/.bash_logout
/home/archlinux/.bash_profile
...

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

[root@centos7 ~]# find / -type f -nouser -nogroup -mtime -3
find: ‘/proc/7720/task/7720/fdinfo/6’: No such file or directory
find: ‘/proc/7720/fdinfo/6’: No such file or directory

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

[root@centos7 ~]# find /etc/ -perm -222 -ls
...
67109020    0 lrwxrwxrwx   1 root     root           14 Dec 26 17:43 /etc/redhat-release -> centos-release
67109021    0 lrwxrwxrwx   1 root     root           14 Dec 26 17:43 /etc/system-release -> centos-release
67700445    0 lrwxrwxrwx   1 root     root           22 Dec 26 17:47 /etc/grub2.cfg -> ../boot/grub2/grub.cfg
...

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

[root@centos7 ~]# find /etc/ -type f -size +1M  
/etc/udev/hwdb.bin
/etc/selinux/targeted/policy/policy.29

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

[root@centos7 ~]# find /etc/init.d/ -perm -113

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

[root@centos7 ~]# find /usr/ ! \( -user root -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d

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

[root@centos7 ~]# find /etc/ ! -perm -222
...
/etc/mailman/templates/zh_CN/postack.txt
/etc/mailman/templates/zh_CN/postauth.txt
/etc/mailman/templates/zh_CN/postheld.txt
/etc/mailman/templates/zh_CN/private.html
...

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

[root@centos7 ~]# find /etc/ -ctime -7 ! \( -user root -o -user hadoop \)

原创文章,作者:N26-西安-方老喵,如若转载,请注明出处:http://www.178linux.com/66702

(1)
N26-西安-方老喵N26-西安-方老喵
上一篇 2017-01-16 19:16
下一篇 2017-01-17 15:07

相关推荐

  • 博客

       这是我的第一篇博客!   平时学习中,总会遇到或大或小的问题,以及一些新的感悟,在当时能够十分清晰记得,但过一些时日,便发现又忘记了。以前十分明白的东西,又变得有些模糊,甚至完全忘记。因此特别需要记录下来,方便日后的查阅或分享给其他遇到类似问题的朋友。    如果以后忘记的某些知识,这时候,翻开以往博客…

    Linux干货 2017-07-11
  • 初窥门径shell脚本

    1.什么是shell脚本    首先它是一个脚本,并不能作为正式的编程语言。因为是跑在linux的shell中,所以叫shell脚本。确切的说shell脚本就是一些命令的集合。 2.写脚本前的一些细节及建议   Shell脚本通常都是以.sh 为后缀名的,这个并不是说不带.sh这个脚本就不能执行,只是大家的一个习惯而已…

    Linux干货 2016-08-12
  • 从Linux小白到大牛——与狼共舞的日子10

    马哥教育网络班21期+第10周课程练习 1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情) POST –> Boot Sequence(BIOS) –> Boot Loader(MBR)   –> Kernel+ramdi…

    Linux干货 2016-12-05
  • btrfs文件系统常用命令使用

    Btrfs,也可称为B-tree,Butter FS,Better FS,是CentOS7中一种新型的文件系统。 核心特性: 1.多物理卷支持,可由多个物理卷(pv)组成,支持raid,以联机添加删除 2.支持写实复制(Copy on Write,Cow) 复制一份修改,改好之后用指针替换,出错时指回原本文件。而不是就地修改 3.数据及元数据校验码:chec…

    Linux干货 2016-03-07
  • grep和正则表达式

    grep       作用:文本搜索工具,根据用户指定的“模式(过滤条件)”对目标文件逐行进行匹配检查;打印匹配到的行;       模式:由正则表达式的元字符及文本所编写出的过滤条件    语法:【选项】【文件】  &…

    2017-08-04
  • 第九周

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash for i in `cut -d':' -f7 /etc/passwd`;do &n…

    Linux干货 2016-09-26