马哥教育第21期-第三周博客作业

1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。
[root@localhost ~]# who | cut -d' ' -f1 | uniq
lqy
root

2、取出最后登录到当前系统的用户的相关信息。
  [root@localhost scripts]# who |tail -1

3、取出当前系统上被用户当作其默认shell的最多的那个shell。
cut -d':' -f7 /etc/passwd |sort|uniq -c | sort -nr | head -1

4、将/etc/passwd中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中。
 sort  -nr -t: -k3 /etc/passwd | head -n 10 | tr 'a-z' 'A-Z' > /tmp/maxusers.txt

5、取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分。
ifconfig | head -2 | tail -1 | grep -o "[^[:space:]].*" | cut -d' ' -f2

6、列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中。
ls /etc/*.conf | tr 'a-z' 'A-Z' > /tmp/etc.conf

7、显示/var目录下一级子目录或文件的总个数。
 du -sh /var

8、取出/etc/group文件中第三个字段数值最小的10个组的名字。
cat /etc/group | sort -t: -k3  -n | head -10 | cut -d: -f1

9、将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中。
cat /etc/fstab /etc/issue > /tmp/etc.test

10、请总结描述用户和组管理类命令的使用方法并完成以下练习:
   (1)、创建组distro,其GID为2016;
      [root@localhost scripts]# groupadd -g 2016 distro
   (2)、创建用户mandriva, 其ID号为1005;基本组为distro;
         [root@localhost scripts]# useradd -u 1005 -g distro mandriva
         [root@localhost scripts]# id mandriva
         uid=1005(mandriva) gid=2016(distro) groups=2016(distro)

   (3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
      [root@localhost scripts]# useradd mageia -u 1100 -d /home/linux
      [root@localhost scripts]# tail -1 /etc/passwd
      mageia:x:1100:1100::/home/linux:/bin/bash

   (4)、给用户mageia添加密码,密码为mageedu;
      [root@localhost scripts]# passwd mageia
   (5)、删除mandriva,但保留其家目录;
      [root@localhost scripts]# userdel mandriva
   (6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
      [root@localhost scripts]# groupadd peguin
      [root@localhost scripts]# useradd slackware -u 2002 -g distro -G peguin
      [root@localhost scripts]# id slackware
      uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin)

   (7)、修改slackware的默认shell为/bin/tcsh;
      [root@localhost scripts]# usermod -s /bin/tcsh slackware
      [root@localhost scripts]# cat /etc/passwd | grep "slackware"
      slackware:x:2002:2016::/home/slackware:/bin/tcsh
      [root@localhost scripts]# chsh -s /bin/tcsh slackware

   (8)、为用户slackware新增附加组admins;
      [root@localhost scripts]# usermod -G admins slackware
      [root@localhost scripts]# id slackware
      uid=2002(slackware) gid=2016(distro) groups=2016(distro),2020(admins)

   (9)、为slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告为3天;
      [root@localhost scripts]# passwd slackware -n 3 -x 108 -w 3
   (10)、添加用户openstack,其ID号为3003, 基本组为clouds,附加组为peguin和nova;
      [root@localhost scripts]# useradd openstack -u 3003 -g clouds -G peguin,nova
      [root@localhost scripts]# id openstack
      uid=3003(openstack) gid=2018(clouds) groups=2018(clouds),2017(peguin),2019(nova)

   (11)、添加系统用户mysql,要求其shell为/sbin/nologin;
      [root@localhost scripts]# useradd -s /bin/nologin mysql
   (12)、使用echo命令,非交互式为openstack添加密码。
      [root@localhost scripts]# echo "passwd" | passwd –stdin openstack

原创文章,作者:21期-扬州-蓝,如若转载,请注明出处:http://www.178linux.com/24253

(0)
21期-扬州-蓝21期-扬州-蓝
上一篇 2016-07-16 22:28
下一篇 2016-07-16 22:28

相关推荐

  • 数组详解

    数组 变量:存储单个元素的内存空间 数组:存储多个元素的连续的内存空间,相当于多个变量的集合          数组名:整个数组只有一个名字     数组索引:编号从0开始,属于数值索引     &n…

    Linux干货 2016-08-24
  • varnish

    Web Page Cache: squid –> varnish程序的运行具有局部性特征:时间局部性:一个数据被访问过之后,可能很快会被再次访问空间局部性:一个数据被访问时,其周边的数据也有可能被访问到 cache:命中 热区:局部性;时效性:缓存空间耗尽:LRU过期:缓存清理 缓存命中率:hit/(hit+miss)(0,1)页面命中率:…

    Linux干货 2017-05-22
  • Linux 第七天: (08月05日) 练习和作业

    Linux 第七天: (08月05日) 练习和作业       1 找出ifconfig命令结果中本机的所有IPv4地址 ifconfig | tr -cs '[0-9].''\n' | sort -ut '.' -k3 -n 或ifconfig | head -2 |…

    Linux干货 2016-08-08
  • 内核编译实际效果演示

    内核编译实际操作效果演示     环境:CentOS7.2,自带内核版本为3.10.0-327.el7.x86_64,下载3.18.41版本进行编译     步骤1:确保开发工具包组已安装     [root@localhost …

    Linux干货 2016-09-13
  • SHELL中的变量

    SHELL中的变量            运行SHELL脚本中的单个命令自然有用,但这有其自身的限制。通常你会需要在SHELL命令使用其他数据来处理信息。这可以通过变量来实现。变量允许你临时性地将信息存储在SHELL脚本中,以便和脚本中的其他命令一起使用。 1 环境变量…

    Linux干货 2017-04-16
  • Linux基础学习总结(一)

    Linux 安装运行步骤: 进入\\172.16.0.1\python10          用户名:python10          密码:python10magedu 进入目录   ftp://172.16.0.1/pub/ISOs/ 下载linux系统镜像文件           CentOS-6.9-x86_64-bin-DVD1.iso     …

    Linux干货 2018-03-16

评论列表(1条)

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

    写的很好,排版还可以在改进一下,加油