grep虐我千百遍,我待grep如初恋

N21第四周博客作业

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

[root@Centos6 ~]# cp -r /etc/skel /home/tuser1
[root@Centos6 ~]#chmod –R og=------ /home/tuser1/
[root@Centos6 ~]# ll -d /home/tuser1
drwx------. 3 root root 4096 7月  14 04:16 /home/tuser1

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

[root@Centos6 ~]# echo "hadoop:x:600:">>/etc/group
[root@Centos6 ~]# tail -1 /etc/group
hadoop:x:600:

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

[root@Centos6 ~]# echo "hadoop:x:600:600::/home/hadoop:/bin/bash">>/etc/passwd
[root@Centos6 ~]# tail -1 /etc/passwd
hadoop:x:600:600::/home/hadoop:/bin/bash

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

[root@Centos6 ~]# cp -r /etc/skel /home/hadoop
[root@Centos6 home]# chmod og=------ /home/hadoop
[root@Centos6 home]# ll
drwx------. 3 root root  4096 7月  14 05:53 hadoop

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

 [root@Centos6 home]# chown -R hadoop:hadoop hadoop
[root@Centos6 home]# ll
drwx------. 3 hadoop hadoop  4096 7月  14 05:53 hadoop

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

[root@Centos6 home]# grep -i '^s.*' /proc/meminfo
SwapCached:         2712 kB
SwapTotal:       2031608 kB
SwapFree:        2021016 kB
Shmem:                28 kB
Slab:             152116 kB
SReclaimable:      95700 kB
SUnreclaim:        56416 kB
[root@Centos6 home]# grep -i '^[s,S].*' /proc/meminfo
SwapCached:         2712 kB
SwapTotal:       2031608 kB
SwapFree:        2021016 kB
Shmem:                28 kB
Slab:               152128 kB
SReclaimable:        95700 kB
SUnreclaim:          56428 kB

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

[root@Centos6 ~]# grep -v '/sbin/nologin' /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
jenkins:x:498:498:Jenkins Continuous Integration Server:/var/lib/jenkins:/bin/false
hadoop:x:500:600::/home/hadoop:/bin/bash

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

[root@Centos6 ~]# grep  '/bin/bash' /etc/passwd
root:x:0:0:root:/root:/bin/bash
hadoop:x:500:600::/home/hadoop:/bin/bash

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

[root@Centos6 ~]# grep -o '\<[0-9]\{1,2\}\>' /etc/passwd
0
0
1
4
7
5
29
29
74
74
72
72
16

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

[root@Centos6 ~]# grep -E '^[[:space:]]+' /boot/grub/grub.conf
root (hd0,0)
kernel /vmlinuz-2.6.32-279.el6.x86_64………….
initrd /initramfs-2.6.32-279.el6.x86_64.img

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

[root@Centos6 ~]# grep -E '^#+[[:space:]]+[[:graph:]]+' /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

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

[root@Centos6 ~]# cls
[root@Centos6 ~]# netstat -tan | grep -E 'LISTEN[[:space:]]+$'
tcp        0      0 0.0.0.0:39750               0.0.0.0:*            LISTEN    
tcp        0      0 0.0.0.0:111                 0.0.0.0:*           LISTEN    
tcp        0      0 0.0.0.0:22                  0.0.0.0:*           LISTEN    
tcp        0      0 127.0.0.1:631               0.0.0.0:*             LISTEN    
tcp        0      0 :::37670                    :::*            LISTEN

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

[root@Centos6 ~]# grep  '^\([[:alpha:]]\+\>\).*\1$' /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
bash:x:541:541::/home/bash:/bin/bash
nologin:x:545:545::/home/nologin:/sbin/nologin

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

[root@Centos6 ~]# grep -E "^(s|S).*" /proc/meminfo
[root@Centos6 ~]# grep '[s,S].*' /proc/meminfo
[root@Centos6 ~]# grep -i '^s.*' /proc/meminfo

 

原创文章,作者:N21-沉舟,如若转载,请注明出处:http://www.178linux.com/24239

(0)
N21-沉舟N21-沉舟
上一篇 2016-07-16 22:27
下一篇 2016-07-16 22:28

相关推荐

  • LVS介绍及工作原理图解

    一、LVS简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器,是一个由章文嵩博士发起的自由软件项目,官方站点是:http://www.linuxvirtualserver.org。现在LVS已经是Linux标准内核的一部分,在Linux2.4内核以前,使用LVS时必须重新编译内核以支持LVS功能模块,但是从Linux2.…

    2017-12-06
  • ​redis cluster 安装指南

    公司的很多项目在使用redis主从。由于coder的各种毁灭性操作,迫切需要一个能带故障恢复的架构。因此新版的cluster,开始了测试。 一、Cluster 理论基础 Cluster介绍 Redis集群是一个提供在多个Redis间节点间共享数据的程序集。 Redis集群并不支持处理多个keys的命令,因为这需要在不同的节点间移动数据,从而达不到像Redis…

    Linux干货 2016-02-14
  • linux 软件包管理

    1、Linux软件包管理 Redhat, SUSE: RPM Redhat Package Manager PRM is Package Manager 前端工具:yum, apt-get 后端工具:RPM, dpt   2、rpm: 数据库:/var/lib/rpm  rpm包: 软件包作者下载源程序,编译配置完成后,制作成rpm包 格…

    Linux干货 2017-08-06
  • echo显示闪烁,screen用法及显示时间的前后

    我们这门今天学习的一些主要内容 标准的命令的格式 命令(COMMAND)  [选项(OPTIONS)….[参数(ARGUMENTS…)] 选项:启用或者关闭命令的某个或某些功能 参数:命令作用的对象,比如文件名,用户名等 首先我们来统计一下学习到的linux的一些基础的命令 who  查询当前用户 hostname 显…

    Linux干货 2016-08-04
  • N27_第五周作业

    一、显示当前系统上root、fedora或者user1用户的默认shell; [root@localhost ~]# grep -E “^(root|fedora|user1)” /etc/passwd | cut -d: -f7 /bin/bash /bin/tcsh /bin/bash二、找出/etc/rc.d/init.d/fu…

    Linux干货 2017-10-20
  • 1021作业

    关于用户和组相关配置文件的总结 /etc/passwd:用户及相关属性信息 在Linux /etc/passwd文件中每个用户都有一个对应的记录行,它记录了这个用户的一些基本属性。系统管理员经常会接触到这个文件的修改以完成对用户的管理工作。这个文件对所有用户都是可读的。但是Linux /etc/passwd文件中都有些什么内容呢? #cat/etc/pass…

    Linux干货 2016-10-24

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-17 20:15

    写的很好,排版也很漂亮,加油