第五周作业

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

相关推荐

  • N25-第一周 总结

    linux bassic The first week of blogging 概要 计算机与操作系统、linux发行版及他们之间联系与区别、Linux的哲学思想、linux系统上命令使用格式及基础命令介绍、linux命令帮助说明、FHS 一、计算机与操作系统 什么是计算机? 电子计算机(computer),亦称电脑,是一种利用电子学原理,根据一系列指令对数…

    Linux干货 2016-12-04
  • N22-第十二周作业

    1、请描述一次完整的http请求处理过程; (1)建立或处理连接:接受请求或拒绝请求 (2)接收请求:接收来自于网络上的主机请求报文中对某特定资源的一次请求的过程 (3)处理请求:对请求报文进行解析,获取客户端请求的资源及请求方法等相关信息 (4)访问资源:获取请求报文中请求的资源 (5)构建响应报文 (6)发送响应报文 (7)记录日志:访问日志和错误日志 …

    Linux干货 2016-11-04
  • linux安全机制与加密工具使用

    一、加密需要和安全机制 1.不加密流量的易受攻击性 密码/数据嗅探 数据操作 验证操作 相当于邮寄明信片 2.不安全的传统协议 telnet、FTP、POP3等等;不安全密码http、sendmail、NFS等等;不安全信息Ldap、NIS、rsh等等;不安全验证 3.NIST定义的安全属性:美国国家标准与技术研究院 1) 保密性:  &…

    Linux干货 2016-09-25
  • 管理用户和组。

    用户的概念        对于计算机的应用,我们大多数都是在储存资料、办公娱乐。我们耗费精力与时间把我们喜欢的一些东西寻找下载在我们的计算机中,这台计算机没有一丁点限制,谁都可以进行访问,那我们所进行存储的一些东西就将变得很不安全,但是我们在给计算机创建一个用户并设置密码之后,其他人没获得…

    Linux干货 2016-10-23
  • ansible高级应用

    上一篇博客介绍了ansible的基础应用Modules,博客地址 http://www.178linux.com/14860 。这次介绍下Ansible的另一个核心模块Playbooks。   Ansible的核心模块:     Ansible core:   &nbs…

    Linux干货 2016-04-18
  • 磁盘管理

    磁盘管理 本文将按顺序以实例演示磁盘管理的所有操作,让我们开始吧! 一,磁盘的添加 ① 先来查看linux系统总共有几个磁盘,由图可知是两个,分别是sda,sdb。我们再加一个,按照磁盘命名顺序,应是sdc,他们都在/dev目录下。 补充: 1,磁盘命名规则: 不同磁盘,按照a-z依次标识,如sda,sdb,sdc 同一磁盘的不同分区,按照1,2,&#823…

    2017-08-19