N25-第四周作业

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

[root@localhost ~]# cp -r /etc/skel /home/tuser1
[root@localhost ~]# ls -ld /home/tuser1
drwxr-xr-x 3 root root 74 Dec 27 10:23 /home/tuser1
[root@localhost ~]# chmod -R g-r,o-r /home/tuser1
[root@localhost ~]# ls -al /home/tuser1
total 16
d-wx--x--x   3 root root   74 Dec 27 10:23 .
drwxr-xr-x. 20 root root 4096 Dec 27 10:23 ..
-rw-------   1 root root   18 Dec 27 10:23 .bash_logout
-rw-------   1 root root  193 Dec 27 10:23 .bash_profile
-rw-------   1 root root  231 Dec 27 10:23 .bashrc
drwx--x--x   4 root root   37 Dec 27 10:23 .mozilla

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

[root@localhost ~]# vim /etc/group
[root@localhost ~]# tail -1  /etc/group
hadoop:x:5006

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

[root@localhost ~]# vim /etc/passwd
[root@localhost ~]# tail -1 /etc/passwd
hadoop:x:3004:5006:/home/hadoop:/bin/bash

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

[root@localhost ~]# cp -r /etc/skel /home/hadoop
[root@localhost ~]# chmod -R g-r,o-r /home/hadoop
[root@localhost ~]# ls -al /home/tuser1
total 16
d-wx--x--x   3 root root   74 Dec 27 10:23 .
drwxr-xr-x. 21 root root 4096 Dec 28 10:09 ..
-rw-------   1 root root   18 Dec 27 10:23 .bash_logout
-rw-------   1 root root  193 Dec 27 10:23 .bash_profile
-rw-------   1 root root  231 Dec 27 10:23 .bashrc
drwx--x--x   4 root root   37 Dec 27 10:23 .mozilla

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

[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop    
[root@localhost ~]# ls -al /home/hadoop
total 16
drwx--x--x   3 hadoop hadoop   74 Dec 28 10:09 .
drwxr-xr-x. 21 root   root   4096 Dec 28 10:09 ..
-rw-------   1 hadoop hadoop   18 Dec 28 10:09 .bash_logout
-rw-------   1 hadoop hadoop  193 Dec 28 10:09 .bash_profile
-rw-------   1 hadoop hadoop  231 Dec 28 10:09 .bashrc
drwx--x--x   4 hadoop hadoop   37 Dec 28 10:09 .mozilla

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

[root@localhost ~]# grep -E "^(s|S)" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13568 kB
Slab:             268852 kB
SReclaimable:     218164 kB
SUnreclaim:        50688 kB

or

[root@localhost ~]# grep -i "^s" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13568 kB
Slab:             268852 kB
SReclaimable:     218164 kB
SUnreclaim:        50688 kB

or

[root@localhost ~]# grep "^[sS]" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13568 kB
Slab:             268852 kB
SReclaimable:     218164 kB
SUnreclaim:        50688 kB

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

[root@localhost ~]# grep "/sbin/nologin$" /etc/passwd | cut -d: -f1

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

[root@localhost ~]# grep "/bin/bash$" /etc/passwd | cut -d: -f1

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:]]*$"
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 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
tcp6       0      0 ::1:6010                :::*                    LISTEN     
tcp6       0      0 ::1:6011                :::*                    LISTEN

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

[root@localhost ~]# grep -E "^([^:]+\>).*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:1015:1015::/home/bash:/bin/bash
nologin:x:1018:1018::/home/nologin:/sbin/nologin

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

(0)
PowercatPowercat
上一篇 2017-01-03 21:13
下一篇 2017-01-03 22:19

相关推荐

  • 马哥教育网络版25期+第一周作业

    1、描述计算机的组成及其功能 计算机是由CPU,控制器,RAM,输入设备,输出设备组成的 2、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别 现如今主流的LINUX发行版系列主要有: Debian,Slackware,Redhat,这些发行版都是基于GUNLinux开发的,不过是由不同的组织或团体开发并发行的。 3、描述Linux的哲学思想,…

    Linux干货 2016-12-05
  • N26_第三周作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 演示: [root@joylin test]# who|cut -d” ” -f1|uniq root gentoo [root@joylin test]# who|cut -d” ” -f1|uniq -c 5 root 1 gentoo 或者 [root@joyl…

    Linux干货 2017-02-21
  • N26-第二周博客作业

    一、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 一) 目录管理命令 1. cd :用于切换目录。命令格式为:cd dirname 命令使用技巧: ~]# cd 进入用户主目录 ~]# cd – 进入上一次所在目录 ~]# cd / 进入根目录 ~]# cd ~ 进入用户主目录 ~]# cd .. 返回上一级…

    2017-03-01
  • vim编辑器作业

    1、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的行首的空白字符 [root@wzc tmp]# vim profile    # By default, we want umask to …

    Linux干货 2016-08-12
  • 上下文管理练习(为加法函数计时)

    上下文管理(为加法函数计时) 为加法函数计时 使用装饰器显示该函数的执行时长 使用上下文管理显示该函数的执行时长 装饰器实现 import time import datetime from functools import wraps def logger(fn): @wraps(fn) # wraps(fn)(wrapper) def wrapper(*…

    2017-11-18
  • 文件管理命令以及bash特性之命令行展开

    一 Linux文件管理 Linux中对文件管理的命令主要有:mkdir rmdir mv rm cp touch file stat等命令 创建目录mkdir mkdir [OPTION]… DIRECTORY… [root@MiWiFi-R3-srv testdir]# mkdir /root/dirtest 在/root下创建一个dirtest的…

    Linux干货 2017-08-13