N26—第三周

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

[root@localhost ~]# who | cut -d ' ' -f 1 |sort -u

l_cong

root

(unknown)

 

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

[l_cong@localhost ~]$ who | tail -1   

l_cong   pts/1        2017-02-15 16:32 (192.168.188.1)

 

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

[root@localhost ~]# cat /etc/passwd | cut -d ":" -f 7 |uniq -c | sort -r -n | head -1

     29 /sbin/nologin

注意:uniq -c :统计重复出现的次数

 

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

[root@localhost ~]# cat /etc/passwd  |  sort  -t ":"  -k 3   -n | tail -10 | tr [a-z] [A-Z]  >> /tmp/maxusers.txt

注意:-n是按照数字大小排序,-k是指定需要排序的栏位,-t指定栏位分隔符为冒号

 

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

[root@localhost ~]# ifconfig | grep inet | head -1 | awk '{print $2}'

192.168.188.66

 

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

[root@localhost test]# ls /etc/*.conf | tr [a-z] [A-Z]  >> /tmp/etc.conf

 

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

[root@localhost ~]# ls /var/  | wc -l

23

 

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

[root@localhost ~]# cat /etc/group | sort -t ":" -k 3 -n |head -10 |cut -d ":" -f 1

root

bin

daemon

sys

adm

tty

disk

lp

mem

kmem

 

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

[root@localhost test]# cat /etc/fstab /etc/issue >>/tmp/etc.test

 

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

   (1)、创建组distro,其GID2016

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

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

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

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

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

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

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

[root@localhost test]# groupadd -g 2016 distro

[root@localhost test]# useradd -u 1005 -g distro mandriva

[root@localhost test]# useradd -u 1100 -d /home/linux mageia

[root@localhost test]# passwd mageia

更改用户 mageia 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

[root@localhost test]# userdel mandriva

[root@localhost test]# groupadd peguin

[root@localhost test]# useradd -u 2002 -g distro  -G peguin slackware

[root@localhost test]# usermod -s /bin/tcsh slackware

[root@localhost test]# groupadd admins

[root@localhost test]# gpasswd -a slackware admins

正在将用户“slackware”加入到“admins”组中

 

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

(0)
N26-xiaocongN26-xiaocong
上一篇 2017-02-15 17:05
下一篇 2017-02-15 17:40

相关推荐

  • N25 – Week 5 blog

    1. 显示当前系统上root, fedora或user1用户的默认shell [root@dhcp-10-129-6-166 ~]# grep -E "root|fedora|user1" /etc/passwd | grep -o "[^…

    Linux干货 2016-12-27
  • CentOS6 编译安装httpd-2.4

       CentOS7的镜像中已经提供了httpd-2.4的rpm包,httpd-2.4相对于httpd2.2有较大的改进,在CentOS6下只能通过Apache官方网站提供的源码包编译安装。    有时候,我们需要应用http-2.4的某些特性,但是因为当前的发行版没有支持,所以我们需要自己编译安装。 httpd-2.…

    Linux干货 2016-07-27
  • 第八周-Linux网络配置,软件安装,bash编程

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别 网桥:一种网络设备,负责网络桥接(network bridging)之用。桥接器将网络的多个网段在数据链路层(OSI模型第2层)连接起来(即桥接)。 集线器(Hub):是指将多条以太网双绞线或光纤集合连接在同一段物理介质下的设备。集线器是运作在OSI模型中的物理层。 二层交换机:工…

    Linux干货 2016-11-14
  • yum相关知识及源码编译安装http

    二.源码编译安装http 获得源码,将源码放在/usr/local/src下,并将其解压缩到此目录下 进入解压缩文件下,查看INSTALL文件 文件内容如下 黄色区域即为安装步骤 在当前目录下执行./configure –prefix=/usr/local/appach2 编译  make make install  把目标文…

    系统运维 2016-08-24
  • Linux系统中的防火墙iptables

    iptables/netfilter——Linux系统下的防火墙 基本原理 防火墙主要功能 工作于主机或者网络边缘,对进出本主机或本网络的报文进行匹配检测,对匹配到规则的报文进行于规则相对应的处理。 防火墙主要分类 按功能分类 主机防火墙网络防火墙 按构成分类 软件防火墙硬件防火墙 Linux防火墙软件iptables/netfilter(以后简称iptab…

    Linux干货 2017-06-13
  • rpm及yum

    库文件 查看二进制程序所依赖的库文件: ldd /PATH/TO/BINARY_FILE [root@localhost ~]# ldd /bin/bash 管理及查看本机装载的库文件: ldconfig /sbin/ldconfig -p:  显示本机已经缓存的所有可用库文件 名及文件路径映射关系 配置文件:/etc/ld.so.conf, /e…

    Linux干货 2016-08-29