马哥教育网络班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

相关推荐

  • bash循环、函数、数组、内置的字符串处理、变量、trap信号捕捉

    流程控制 过程式编程语言: 顺序执行 如果是命令写错了,可以继续往下执行;但当语法错误时则不会往下继续执行; 选择执行 循环执行 条件选择:if语句 单分支 if 判断条件;then 条件为真的分支代码 fi 双分支 if 判断条件; then 条件为真的分支代码 else 条件为假的分支代码 fi 多分支 if 判断条件1; then 条件为真的分支代码 …

    Linux干货 2017-05-21
  • 逻辑卷实战演练

    1、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录 2、新建用户archlinux,要求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录 3、扩展testlv…

    Linux干货 2016-09-01
  • Homework Week-7 RAID及bash编程

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

    Linux干货 2016-09-26
  • 零距离接触软RAID0和RAID5以及逻辑卷LVM

    一、创建一个可用空间为1G的RAID1设备,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录 1、首先手动给虚拟机添加两块硬盘 2、添加硬盘后,无需关机,直接让内核扫描添加的磁盘 [root@centos6 ~]# echo '- – -' >&nbsp…

    Linux干货 2016-09-01
  • linux网络属性命令操作介绍(第十一天)

            linux网络属性常用命令有ifconfig\route\ip命令,centos7 的还是nmcli\nmtui。     网络属性的三大文件:修改DNS的文件/etc/resolv.conf  、修改网卡IP地址/etc/sysconfig/…

    Linux干货 2016-06-01

评论列表(1条)

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

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