第五周作业

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
下一篇 2017-01-17

相关推荐

  • poweroff

    poweroff命令详解

    Linux干货 2018-03-04
  • 新手报到

    在开班的第一天为自己立下flag,看毕业时能否实现自己的预期。

    2018-03-26
  • 日志分析工具Awstats实战之Apache篇-多站点日志分析

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1318052 前面两篇都在讲述如何去部署nginx下的awstats日志分析工具,现在终于轮到apache。作为老牌的网页服务器,awstats对apache…

    Linux干货 2016-08-15
  • 第六周作业

    第六周作业 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; cp /etc/rc.d/rc.sysinit /tmp vim /tmp/rc.sysinit :进入末行模式 % s/^[[:space:]]/#&…

    Linux干货 2016-10-09
  • fdisk命令

    fdisk命令用于观察硬盘实体使用情况,也可对硬盘分区。

    2017-12-05
  • yum仓库搭建

    两台主机: 一台centos7  客户机 一台centos6  服务器 准备工作 1.查看是否共享服务是否可用 httpd或vsftpd 是否安装。确认安装之后选择vsftpd为共享服务/var/www/html和/var/ftp/pub为共享目录。 这里使用vsftpd,/var/ftp/pub这个目录为共享目录 在这个目录下建立一个独立的文件夹 [roo…

    2017-12-01