马哥教育网络21期+第4周博客练习。

马哥教育网络21期+第1周博客练习。

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

[root@CentOS6 ~]# cp -a /etc/skel/ /home/tuser1
[root@CentOS6 ~]# chmod -R 700 /home/tuser1
[root@CentOS6 ~]# ll -d /home/tuser1
drwx------. 4 root root 4096 7月   8 23:25 /home/tuser1
[root@CentOS6 tuser1]# ls -al /home/tuser1/
总用量 28
drwx------. 4 root root 4096 7月   8 23:25 .
drwxr-xr-x. 6 root root 4096 7月  31 16:27 ..
-rwx------. 1 root root   18 5月  11 07:21 .bash_logout
-rwx------. 1 root root  176 5月  11 07:21 .bash_profile
-rwx------. 1 root root  124 5月  11 07:21 .bashrc
drwx------. 2 root root 4096 11月 12 2010 .gnome2
drwx------. 4 root root 4096 1月  24 2016 .mozilla

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

[root@CentOS6 tuser1]# vim /etc/group
hadoop:x:3000
[root@CentOS6 tuser1]# tail -1 /etc/group
hadoop:x:3000:

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

[root@CentOS6 tuser1]# vim /etc/passwd
hadoop:x:3000:3000:HADOOP:/home/hadoop:/sbin/nologin
[root@CentOS6 tuser1]# id hadoop
uid=3000(hadoop) gid=3000(hadoop) 组=3000(hadoop)
[root@CentOS6 tuser1]# finger hadoop
Login: hadoop         			Name: HADOOP
Directory: /home/hadoop             	Shell: /sbin/nologin
Never logged in.
No mail.
No Plan.

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

[root@CentOS6 tuser1]# cp -a /etc/skel/ /home/hadoop
[root@CentOS6 tuser1]# chmod 700 /home/hadoop
[root@CentOS6 tuser1]# ll -d /home/hadoop
drwx------. 4 root root 4096 7月   8 23:25 /home/hadoop

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

[root@CentOS6 tuser1]# chown -R hadoop:hadoop /home/hadoop
[root@CentOS6 tuser1]# ll -d /home/hadoop
drwx------. 4 hadoop hadoop 4096 7月   8 23:25 /home/hadoop
[root@CentOS6 tuser1]# ll -la /home/hadoop
总用量 28
drwx------. 4 hadoop hadoop 4096 7月   8 23:25 .
drwxr-xr-x. 7 root   root   4096 7月  31 16:35 ..
-rw-r--r--. 1 hadoop hadoop   18 5月  11 07:21 .bash_logout
-rw-r--r--. 1 hadoop hadoop  176 5月  11 07:21 .bash_profile
-rw-r--r--. 1 hadoop hadoop  124 5月  11 07:21 .bashrc
drwxr-xr-x. 2 hadoop hadoop 4096 11月 12 2010 .gnome2
drwxr-xr-x. 4 hadoop hadoop 4096 1月  24 2016 .mozilla

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

[root@CentOS6 tuser1]# grep -i '^s.*' /proc/meminfo 
[root@CentOS6 tuser1]# grep '^[sS].*' /proc/meminfo
[root@CentOS6 tuser1]# egrep '^(S|s).*' /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       4046844 kB
SwapFree:        4046844 kB
Shmem:              1172 kB
Slab:             191912 kB
SReclaimable:     120636 kB
SUnreclaim:        71276 kB

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

[root@CentOS6 tuser1]# grep -v '/sbin/nologin' /etc/passwd|awk -F':' '{print $1}'
root
sync
shutdown
halt
santi

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

[root@CentOS6 tuser1]# grep '/bin/bash' /etc/passwd |cut -d':' -f1
root
santi

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

[root@CentOS6 tuser1]# grep -o '[0-9][0-9]\?' /etc/passwd
0
0
1
11
0
12
10
...

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

[root@CentOS6 tuser1]# grep '^[[:space:]].*' /boot/grub/grub.conf 
root (hd0,0)
kernel /vmlinuz-2.6.32-642.3.1.el6.x86_64 ro root=/dev/mapper/vg_centos6-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=vg_centos6/lv_swap.UTF-8 rd
_LVM_LV=vg_centos6/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet crashkernel=auto initrd /initramfs-2.6.32-642.3.1.el6.x86_64.img
root (hd0,0)
kernel /vmlinuz-2.6.32-642.1.1.el6.x86_64 ro root=/dev/mapper/vg_centos6-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=vg_centos6/lv_swap.UTF-8 rd
_LVM_LV=vg_centos6/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet crashkernel=auto initrd /initramfs-2.6.32-642.1.1.el6.x86_64.img
...

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

grep '^#[[:space:]]\+.*[[:space:]]\+' /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.
...

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

[root@CentOS6 tuser1]# netstat -tan|grep 'LISTEN[[:space:]]*'
tcp        0      0 0.0.0.0:60364               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 127.0.0.1:25                0.0.0.0:*                   LISTEN

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

grep '^\([[:alpha:]].*\>\).*\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:3005:3005::/home/bash:/bin/bash
nologin:x:3008:3008::/home/nologin:/sbin/nologin

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

[root@CentOS6 tuser1]# grep -i '^s.*' /proc/meminfo 
[root@CentOS6 tuser1]# grep '^[sS].*' /proc/meminfo
[root@CentOS6 tuser1]# egrep '^(S|s).*' /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       4046844 kB
SwapFree:        4046844 kB
Shmem:              1172 kB
Slab:             191912 kB
SReclaimable:     120636 kB
SUnreclaim:        71276 kB

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

[root@CentOS6 ~]# grep -v '/sbin/nologin' /etc/passwd |cut -d":" -f1
root
sync
shutdown
halt
santi
bash
testbash
basher

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

[root@CentOS6 ~]# grep '/bin/bash$' /etc/passwd |cut -d":" -f1
root
santi
bash
testbash
basher

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

[root@CentOS6 tuser1]# grep -o '[0-9][0-9]\?' /etc/passwd
0
0
1
11
0
12
10
...

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

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

相关推荐

  • Ansible+Corosync+Pacemaker+nfs实现http高可用

    目录: (一)实验环境 (二)准备工作 (三)为node1和node2配置基础配置 (四)使用ansible部署nfs (五)使用ansible部署corosync和pacemaker (六)使用ansible安装crmsh工具 (七)使用crmsh配置http高可用 (八)验证 (九)需要注意的地方 (一)实验环境 1.1、环境拓扑 1.2、所需系统 4台…

    Linux干货 2016-04-29
  • Apache运行机制剖析

    1. B/S交互过程 浏览器(Browser)和服务器(Web Server)的交互过程:   1、  浏览器向服务器发出HTTP请求(Request)。 2、  服务器收到浏览器的请求数据,经过分析处理,向浏览器输出响应数据(Response)。 3、  浏览器收到服务器的响应数据,经过分析处理,将最终结果显示在浏览…

    Linux干货 2015-04-10
  • grep是个什么鬼

    正则表达式   一个正则表达式是一个描述了一个字符串集合的模式。正则表达式的构造类似于算术表达式,使用各种各样的操作符来将更小的表达式连在一起。 Grep能理解两种不同版本的正则表达式语法:“basic”和“extended”。在GNU grep中,两种语法可以实现的功能是没有区别的。在其他实现中,基本(basic)正则表达式表达能力要弱一点。下面…

    Linux干货 2017-04-17
  • 马哥教育网络班20期第3周课程练习

    答: 1、 [root@totooco ~]# who | cut -c1-9 | sort -u 2、 [totooco@totooco ~]$ who | cut -c1-9 | head -1 3、 [root@totooco ~]# cat /etc/passwd | cut -d: -f7 | grep -v /sbin/nologin | sor…

    Linux干货 2016-06-23
  • 硬链接和软链接的区别

    硬链接和软链接的区别 1、概念 在linux中,链接可分为两种:一种为硬链接,另一种为软链接。硬链接:ln 源文件 目标文件软链接:ln -s(soft)源文件 目标文件 硬链接 硬链接是指通过索引节点inode来进行链接。linux系统中每个文件对应一个inode,并且允许多个文件名指向用一个inode。这种情况的文件就成为硬链接。它的作用之一就是允许一个…

    Linux干货 2017-07-23
  • 模拟网络访问解析

    搭建局域网DNS解析,具体实现功能如下图 注:该测试只有正向解析 项目流程图 1. 项目前准备关闭防火墙和SELINUX,配置网络 ①开启8台机器 ②关闭防火墙及selinux iptables -vnL #查看防火墙状态 systemctl stop firewall #关闭防火墙 getenforce #查看SELinux状态 setenforce 0 …

    2018-06-04

评论列表(1条)

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

    写的很好,排版也很棒,加油,最后一个最好是用{}做