正则表达式应用

1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。

   cp -a /etc/skel /home/tuser1
   chmod g-x /home/tuser1/
   chmod o-x /home/tuser1/

2、编辑/etc/group文件,添加组hadoop。

   vim进入/etc/group,新增:hadoop:x:505:

3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。

   hadoop:x:503:505::/home/hadoop:/bin/bash

4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。

   cp -a /etc/skel /home/hadoop
   chmod g-x /home/hadoop
   chmod o-x /home/hadoop

5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。

    chown -R hadoop:hadoop /home/hadoop

6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;

   grep "^[Ss].*" /proc/meminfo
   grep -i "^s.*" /proc/meminfo

7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;

   egrep "[^/sbin/nologin]$" /etc/passwd | cut -d: -f1

8、显示/etc/passwd文件中其默认shell为/bin/bash的用户;

   grep '/bin/bash$' /etc/passwd | cut -d: -f1

9、找出/etc/passwd文件中的一位数或两位数;

   grep "\<[0-9]\{2,3\}\>" /etc/passwd

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

   grep '^[[:space:]].*' /boot/grub/grub.conf

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

   grep '^#[[:space:]]\+[^[:space:]]\+' /etc/rc.d/rc.sysinit

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

   netstat -tan | grep "LISTEN[[:space:]]\+$"

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

   grep "^\([[:alnum:]]\+\>\).*\1$" /etc/passwd

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

赞 (0)
evergreen1989evergreen1989
上一篇 2016-12-24 19:38
下一篇 2016-12-25 01:05

相关推荐

  • 文件系统管理&raid&脚本编程之参数、算数运算练习

    1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; (1) ~]# fdisk /dev/sdb Welcome to…

    Linux干货 2016-11-08
  • 处理交换文件和分区

    处理交换文件和分区 交换分区是系统RAM的补充   基本设置包括:  1 创建交换分区或者文件  2 使用mkswap写入特殊签名  3 在/etc/fstab文件中添加适当的条目  4 使用swapon -a 激活交换空间 挂载交换分区  启用:swapon swapon [OPTION]……

    Linux干货 2016-09-01
  • N22-冥界之王-第9周作业

    第九周    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);   分别这两类用户的个数;通过字符串比较来实现;     declare -a shell  &n…

    Linux干货 2016-11-01
  • 磁盘管理作业

    创建一个2G的文件系统,块大小为2048byte, 预留1%可用空间,文件系统ext4,卷标为TEST,要求此分区开机后自动挂载至/testdir目录,且默认有acl挂载选项 [root@English6 ~]# fdisk /dev/sdc Device contains neither a&nb…

    Linux干货 2016-09-01
  • 条件判断工具 test or [ ]

    概述         条件判断是学习shell脚本之前要掌握的重点基础。条件判断分为以下几类:文件判断、数值判断、字符判断。而文件判断还可以细分到:文件类型判断、文件权限判断、文件所属判断、文件之间属性判断;      &nbsp…

    Linux干货 2016-02-14

评论列表(1条)

  • 马哥教育
    马哥教育 2017-01-04 16:31

    第九个是匹配1到2位数哦