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

1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。

who | cut -d" " -f 1 |sort |uniq

2、取出最后登录到当前系统的用户的相关信息。

last | head -1

3、取出当前系统上被用户当作其默认shell的最多的那个shell。

cat /etc/passwd | cut -d":" -f 7 | sort | uniq -c | sort -rn | head -1

4、将/etc/passwd中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中。

cat /etc/passwd | sort -t":" -k 3 -rn | cut -d":" -f 1 | tr "a-z" "A-Z" | head > /tmp/maxusers.txt

5、取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分。

ifconfig | grep '\<inet\>' | sed 's/^[ \t]*//g' |cut -d" " -f 2

6、列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中。

# ls /etc/*.conf | tr "a-z" "A-Z" >> /tmp/etc.conf

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

# ls -al /var | wc -l

8、取出/etc/group文件中第三个字段数值最小的10个组的名字。

# sort -n -t":" -k 3 /etc/group | head

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

# cat /etc/{fstab,issue} > /tmp/etc.test

10、请总结描述用户和组管理类命令的使用方法并完成以下练习:

   (1)、创建组distro,其GID为2016;

[root@centos7study ~]# groupadd -g 2016 distro

  (2)、创建用户mandriva, 其ID号为1005;基本组为distro;

[root@centos7study ~]# useradd -u 1005 -g 2016 mandriva

   (3)、创建用户mageia,其ID号为1100,家目录为/home/linux;

[root@centos7study ~]# useradd -u 1100 -d /home/linux mageia

   (4)、给用户mageia添加密码,密码为mageedu;

[root@centos7study ~]# passwd mageia
Changing password for user mageia.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

   (5)、删除mandriva,但保留其家目录;

[root@centos7study ~]# userdel mandriva

   (6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;

[root@centos7study ~]# groupadd peguin
[root@centos7study ~]# useradd -u 2002 -g distro -G peguin slackware

   (7)、修改slackware的默认shell为/bin/tcsh;

[root@centos7study ~]# usermod -s /bin/tcsh

   (8)、为用户slackware新增附加组admins;

[root@centos7study ~]# groupadd admins
[root@centos7study ~]# usermod  -a -G admins slackware

   (9)、为slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告为3天;

[root@centos7study ~]# passwd -n 3 -x 180 -w 3 slackware

   (10)、添加用户openstack,其ID号为3003, 基本组为clouds,附加组为peguin和nova;

[root@centos7study ~]# groupadd nova
[root@centos7study ~]# groupadd clouds
[root@centos7study ~]# useradd -u 3003 -g clouds -G peguin,nova openstack

   (11)、添加系统用户mysql,要求其shell为/sbin/nologin;

[root@centos7study ~]# useradd -r -s /sbin/nologin mysql

   (12)、使用echo命令,非交互式为openstack添加密码。

[root@centos7study ~]# echo "magedu" | passwd --stdin openstack
Changing password for user openstack.
passwd: all authentication tokens updated successfully.

原创文章,作者:N21-孟然,如若转载,请注明出处:http://www.178linux.com/25354

(0)
N21-孟然N21-孟然
上一篇 2016-07-29 12:11
下一篇 2016-07-29 15:22

相关推荐

  • zabbix之报警功能的实现

    一、注册微信公众号 首先申请微信公众平台https://mp.weixin.qq.com/一个人最多申请5个公众号,所以还是可以的 申请完之后就可以根据腾讯的提示使用微信公众号了,然后用你自己的微信扫描关注微信号。 就可以看到用户数了,接下来的就要使用的用户的微信ID号了。点击用户查看用户的微信ID号。在浏览器查看用户的微信ID号。就是那个红色的ID了。 h…

    2014-11-12
  • 马哥教育网络班20期+第五周博客作业

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; ]# grep  "^[[:space:]]\+" /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; ]#…

    Linux干货 2016-07-12
  • Linux的发展史

    Linux的诞生 1987年荷兰阿姆斯特丹Vrije大学的Andrew S.Tanenbaum 教授为了让学生们更了解操作系统而参照Unix系统编写了Minix系统。在1988年芬兰赫尔辛基大学迎来了一位新生Linus Benedict Torvalds ,他在学习了Minix系统后,以此为平台和指导开发出了Linux。在1991年8月Linus Toval…

    Linux干货 2016-10-19
  • LVM管理

    LVM管理

    2017-12-28
  • Linux网络管理命令的使用

    网络管理命令 ip命令 配置Linux网络属性:ip命令,不过该命令的操作只是临时操作,重启以后配置丢失 ip-show / manipulate routing, devices, policy routing and tunnels ip [ OPTIONS ] OBJECT { COMMAND | help }    &n…

    Linux干货 2016-09-11
  • Systemd——CentOS7的init

    Systemd:     POST –> Boot Sequeue(BIOS) –> Bootloader(MBR) –> kernel(ramdisk) –> rootfs –> /sbin/init init:   &nbsp…

    Linux干货 2016-09-20

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-29 16:01

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