第五周作业

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

相关推荐

  • Linux进程管理

    内核的功能:     进程管理 文件系统 网络功能 内存管理 驱动程序 安全功能等     rocess:运行中的程序的一个副本,是被载入内存的一个指令集合      进程ID(Process ID,PID)号码被用来标记各个进程 UID,GID,和…

    Linux干货 2016-09-12
  • Linux系统命令格式及基础命令、帮助信息。

    一、Linux系统上的命令使用格式 命令的语法通用格式:                 # COMMAND OPTIONS ARGUMENTS     &nb…

    Linux干货 2016-10-30
  • bash特性、bash编程

    bash基础特性: 命令行展开:~,{} 命令别名:alias,unalias 命令历史:history 命令和路径补全:$PATH glob通配符:*,?,[],[^], 快捷键:Ctrl+{a,e,l,c,u,k} 命令hash:   bash通配符及特殊符号: 通配符: ?:任意一个字符; *:匹配任意个任意字符; []:匹配括号内的任意一个…

    Linux干货 2018-03-21
  • 数组

    数组 变量:存储单个元素的内存空间 数组:存储多个元素的连续的内存空间,相当于多个变量的集合 数组名和索引 索引:编号从0开始,属于数值索引 注意:索引可支持使用自定义的格式,而不仅是数值格式,即为关联索引, 八十的数组支持稀疏格式(索引不连续 声明数组: Declare -a ARRAY_NAME Declare -A ARRAY_NAME:关联数组 注意…

    Linux干货 2018-01-02
  • Homework Week-4 grep用法

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp -r /etc/skel /home/tuser1 chmod  -R g=,o= /home/tuser1 2、编辑/etc/group文件,添加…

    Linux干货 2016-09-06