马哥教育网络班20期第5周课程练习

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

[root@totooco6 ~]# grep "^[[:space:]]\+.*" /boot/grub/grub.conf


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

[root@totooco6 ~]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit

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

[root@totooco /]# netstat -tan | grep "LISTEN[[:space:]]\?"

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

[root@totooco6 ~]# grep '\(\<[[:alnum:]]\+\>\).*\1$' /etc/passwd

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

[root@totooco6 ~]# grep -E "^(root|fedora|user1)\>" /etc/passwd |cut -d: -f7

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

[root@totooco6 ~]# grep "\<.*\>()" /etc/rc.d/init.d//functions

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

    扩展:取出其路径名

[root@totooco ~]# echo "/etc/sysconfig/network" | egrep -o "[^/]+/?$"
network
[root@totooco ~]# echo "/etc/sysconfig/network" | egrep -o ".*/"
/etc/sysconfig/

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

[root@totooco ~]# ifconfig |grep -E "\<[1-9]|[1-9][1-9]|1[1-9][1-9]|2[0-4][0-9]|25[0-5]\>"

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

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

[root@totooco ~]# grep -o "[^[:space:]]*@[^[:space:]]*" /var/spool/mail/root


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

[root@totooco ~]# find /var/ -user root -group mail

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

[root@totooco ~]# find / -nouser -nogroup
find: ‘/proc/6181/task/6181/fd/6’: 没有那个文件或目录
find: ‘/proc/6181/task/6181/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/6181/fd/6’: 没有那个文件或目录
find: ‘/proc/6181/fdinfo/6’: 没有那个文件或目录

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

[root@totooco ~]# find / -nouser -nogroup -atime 3
find: ‘/proc/6183/task/6183/fd/6’: 没有那个文件或目录
find: ‘/proc/6183/task/6183/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/6183/fd/6’: 没有那个文件或目录
find: ‘/proc/6183/fdinfo/6’: 没有那个文件或目录

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

[root@totooco ~]# find /etc/ -perm 222

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

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

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

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

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

[root@totooco ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \)

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

[root@totooco ~]# find /etc/ -not -perm /222


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

[root@totooco ~]# find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \)


原创文章,作者:Net20_totooco,如若转载,请注明出处:http://www.178linux.com/21304

(0)
Net20_totoocoNet20_totooco
上一篇 2016-07-04
下一篇 2016-07-04

相关推荐

  • linux 进程及作业管理

     1、Process: 运行中的程序的一个副本,是被载入内存的一个指令集合 进程ID(Process ID,PID)号码被用来标记各个进程 UID、GID、和SELinux语境决定对文件系统的存取和访问权限, 通常从执行进程的用户来继承 存在生命周期 Uninterruptible sleep: 不可中断的睡眠 Interruptible slee…

    Linux干货 2017-08-28
  • 搭建一个LVS-nat,负载均衡 WordPress

    准备工作 首先配置一下环境:       Directory:ens33 172.16.251.73 ens37 192.168.42.1       RS1:192.168.42.132  gw 192.168.42.1   &…

    2017-06-22
  • linux之文本处理工具

    今天来聊一聊关于linux中处理shell的文本工具,主要说说以下命令:  · 文件查看命令:cat、tac、  · 分页查看文件内容:more、less  · 显示文本前行或后行内容:head、tail  · 按列抽取文本:cut  · 合并文件:paste  · 文…

    2017-07-29
  • shell脚本编程的执行语句

    顺序执行     从上到下逐条执行命令,执行完所有命令及退出。 选择执行     (1)&&,||     &&:代表and,&&左侧为真右侧则执行     ||:代表or…

    Linux干货 2016-08-24
  • linux基础(一)

    一些运维的基本命令和作用。

    Linux笔记 2018-04-01
  • useradd命令

    useradd创建用户 使用格式: useradd[options] LOGIN -c:备注信息保存在passwd的备注栏中。 -d:用户登入时的主目录 -e:账号的失效日期,缺省表示永久有效。 -f:密码过期后多少天关闭该账号。 -g:用户所属组。 -G:用户所属的附加群组。 -m:自动创建用户的登入目录。 -M:不要自动创建用户的登入目录。 -n:取消创…

    Linux干货 2017-12-20

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-04 13:47

    写的很好,排版很棒,加油