马哥教育网络班21期+第4周课程练习

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

[root@localhost skel]# cp -a /etc/skel/ /home/tuser1
[root@localhost skel]# chmod -R 700 /home/tuser1/
[root@localhost skel]# ll -a /home/tuser1/
总用量 12
drwx------. 3 root root  74 7月  31 19:21 .
drwxr-xr-x. 4 root root  29 7月  31 19:21 ..
-rwx------. 1 root root  18 7月  31 19:21 .bash_logout
-rwx------. 1 root root 193 7月  31 19:21 .bash_profile
-rwx------. 1 root root 231 7月  31 19:21 .bashrc
drwx------. 4 root root  37 7月  31 19:21 .mozilla

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

[root@localhost ~]# vim /etc/group
hadoop:x:5000:

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

[root@localhost ~]# vim /etc/passwd
hadoop:x:2000:5000:hadoop:/home/hadoop:/bin/bash
[root@localhost ~]# id hadoop
uid=2000(hadoop) gid=5000(hadoop) 组=5000(hadoop)

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

[root@localhost ~]# cp -a /etc/skel /home/hadoop
[root@localhost ~]# chmod -R 700 /home/hadoop
[root@localhost ~]# ll -a /home/hadoop/
总用量 12
drwx------. 3 root root  74 7月  22 14:17 .
drwxr-xr-x. 5 root root  42 7月  31 19:43 ..
-rwx------. 1 root root  18 11月 20 2015 .bash_logout
-rwx------. 1 root root 193 11月 20 2015 .bash_profile
-rwx------. 1 root root 231 11月 20 2015 .bashrc
drwx------. 4 root root  37 7月  22 14:16 .mozilla

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

[root@localhost ~]# chown -R hadoop /home/hadoop/
[root@localhost ~]# chgrp -R hadoop /home/hadoop/

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

[root@localhost ~]# grep '^[sS]' /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       8491004 kB
SwapFree:        8491004 kB
Shmem:             11104 kB
Slab:             431004 kB
SReclaimable:     328664 kB
SUnreclaim:       102340 kB
[root@localhost ~]# grep -i '^s' /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       8491004 kB
SwapFree:        8491004 kB
Shmem:             11104 kB
Slab:             431000 kB
SReclaimable:     328664 kB
SUnreclaim:       102336 kB

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

[root@localhost ~]# 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
zyf:x:1000:1000:zyf:/home/zyf:/bin/bash
hadoop:x:2000:5000:hadoop:/home/hadoop:/bin/bash

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

[root@localhost ~]# grep '/bin/bash$' /etc/passwd
root:x:0:0:root:/root:/bin/bash
zyf:x:1000:1000:zyf:/home/zyf:/bin/bash
hadoop:x:2000:5000:hadoop:/home/hadoop:/bin/bash

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

[root@localhost ~]# grep "\<[0-9]\{1,2\}\>" /etc/passwd

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

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

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

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

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

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]"

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

[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
[root@localhost ~]# grep "^\([[:alnum:]]\+\>\).*\1$" /etc/passwd

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

[root@localhost ~]# grep "^[Ss]" /proc/meminfo
[root@localhost ~]# grep -i "^s" /proc/meminfo
[root@localhost ~]# grep -v "^[^Ss]" /proc/meminfo

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

[root@localhost ~]# grep -v "/sbin/nologin$" /etc/passwd

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

[root@localhost ~]# grep "/bin/bash$" /etc/passwd

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

[root@localhost ~]# grep "\<[0-9]\{1,2\}\>" /etc/passwd

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

(0)
BazingaBazinga
上一篇 2016-08-02 10:52
下一篇 2016-08-02 10:53

相关推荐

  • Centos6.8 搭建LAMP平台

    Centos6.8 搭建LAMP平台 §·运行环境介绍 LAMP的运行环境介绍: L代表: Linux  Centos 6.8 A代表: apache  httpd-2.2.15-53.el6.centos.x86_64 M代表:MySQL  mysql-server-5.1.73-7.el6.x86_64 P代表: php &…

    Linux干货 2016-10-12
  • shell 编程基础

    命令错误 后面的命令继续执行 语法错误 后面的命令不执行 bash -n 检查语法错位 bash -x 查看脚本的执行过程 【排错】 ++文件属性上的 显示是嵌套命令 变量 引用变量要加$符号 echo 是显示字符串的 如果命令能识别变量 可以不加$ 识别不了就压加$ 变量尽量用“ ”引起来 保留里面的格式 name =`whoami` echo &#822…

    Linux笔记 2018-04-15
  • 关于IO的同步,异步,阻塞,非阻塞

    上次写了一篇文章:Unix IO 模型学习。恰巧在这次周会的时候,@fp1203 (goldendoc成员之一) 正好在讲解poll和epoll的底层实现。中途正好讨论了网络IO的同步、异步、阻塞、非阻塞的概念,当时讲下来,大家的理解各不相同,各执己见。搜索了网络上的一些文章,观点也各不相同,甚至连wiki也将异步和非阻塞当成一个概念在解释。  &…

    Linux干货 2015-04-02
  • Linux的简介

    Linux的简介 冯诺依曼体系结构 主要特点:使用存储器,采用二进制(据说,采用二进制的灵感来源于中国的八卦,2变4,4变8…) 体系介绍:其由几大部分组成,输入设备,运算器,控制器,内部存储器,外部存储器,输出设备。 目前,输入设备就是指键盘鼠标, 运算器和控制器现在统称CPU。其实已经内置了两个功能。 内部存储器就是内存,某种意义上,缓存也算…

    Linux干货 2016-10-28
  • Nginx lnmp环境及https的实现

    一、http事务简明  request: <method> <URL> <VERSION> MHADERS <body> response: <version><status><reason phrase> <HEADERS> … <body&…

    2014-09-25
  • tom猫—–(Tomcat详解)

    目录 安装tomcat tomcat目录结构及配置文件构成以及主配置文件server.xml ,tomcat中的组件 实现反代tomcat的方法 nginx+tomcat cluster http(mod_porxy_http)+tomcat cluster http(mod_porxy_ajp)+tomcat cluster http(mod_jk)+to…

    2017-11-16

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-02 11:46

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