第五周作业

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

相关推荐

  • 磁盘管理(二)之swap、dd工具使用

    磁盘管理(二)之swap、dd工具使用   一、挂载点和/etc/fstab   (1)配置文件/etc/fstab,当系统启动时,自动加载该文件,会把写在配置文件里面的所有挂载点全部自动挂载上去,只要按照格式写,就不会丢失。   (2)文件挂载配置文件,如下图:    &nbs…

    Linux干货 2016-08-29
  • 进程管理

    1、ps命令 查看当前时刻的进程状态,通过此命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等 进程状态:     运行态:running     就绪态:ready     睡眠态: &…

    Linux干货 2016-09-10
  • #招聘福利#饿了么/运维核心岗位/上海

    饿了么/运维核心岗位/上海 待遇面谈 具体岗位:         应用运维,核心岗位,负责商家订单系统,有之前的学长带着成长 要求:     1、1-2年以上工作经验,     2、熟悉shell和python,    &nbsp…

    Linux干货 2016-03-18
  • 系统自动化安装和SELinux

    一、知识整理 1、anaconda系统安装程序:默认图形启动; 使用光盘启动,在选择模式界面tab键在后面增加text或按下ESC键,输入lnux text进入字符界面安装。 2、创建kickstart文件: 直接手动编辑:依据模板修改,/root目录下的anaconda.cfg 使用创建工具创建:system-config-kickstart,图形化工具:…

    Linux干货 2016-09-26
  • vim 编辑器介绍

         vi: Visual Interface ,文本编辑器  文本:ASCII, Unicode  文本编辑种类: 行编辑器: sed 全屏编辑器:nano, vi vim – Vi Improved  其他编辑器: gedit 一个简单的图形编辑器 gvim 一个 Vim 编辑器…

    2017-06-03
  • Linux运维学习历程-第六天-Linux重定向和管道

    Linux运维学习历程-第六天-Linux重定向和管道 2 本章内容我们将学习linux中的重定向和管道两大用法   I/O输入与输出设备   重定向   管道   tee命令与tr命令 一、I/O设备   1、什么是I/O设备   管理和控制计算机的所有输入/输出(I/O)设备是操作系统…

    Linux干货 2016-08-03