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
下一篇 2017-02-15

相关推荐

  • 【招聘】北京/互联网/运维工程师/7-15K/双休,五险一金

    岗位职责:   1、负责服务器的规划、调试优化、日常监控、故障处理、数据备份、日志分析等工作;   2、参与运维流程制定,确保任何突发情况都能高效响应;  3、负责服务器部署,对服务器构架和网络进行优化和改进;  4、负责运维相关数据的收集、分析和总结;  5、负责技术运维相关的文档、手册…

    Linux干货 2016-04-16
  • ldirectord 结合ipvsadm 配置nat,dr模型

    ldirectord 结合ipvsadm 配置nat,dr模型  一、nat模型 1、 drector # wget ftp://172.16.0.1/pub/Sources/7.x86_64/crmsh/ldirectord-3.9.6-0rc1.1.1.x86_64.rpm # yum -y install nginx (同…

    Linux干货 2016-11-24
  • btrfs初步应用

    前言 一种技术要知其然,还要知其所以然。 Btrfs文件系统 Btrfs(B-tree文件系统,通常念成Butter FS,Better FS或B-tree FS),一种支持写入时复制(COW)的文件系统,运行在Linux操作系统,采用GPL授权。Oracle于2007年对外宣布这项计划,并发布源代码,在2014年8月发布稳定版目标是替换Linux目前的ex…

    Linux干货 2016-05-22
  • Linux进程管理

    一:进程的概念     1)进程:process,运行中的程序的一个副本的某部分,之所以说是副本的一部分是因为一个程序可以多个用户同时以不同格式运行,如两个用户都在运行ls,一个运行的是ls -h ,另一个运行的是ls -l,那么这两个用户运行的程序代码肯定是不一样的而且不是程序的所有代码;进程有生命周期; &nbsp…

    2017-03-26
  • 正则表达式字符集

    POSIX Description ASCII Unicode Shorthand Java [:alnum:] Alphanumeric characters [a–zA–Z0–9] [\p{L}\p{Nl}  \p{Nd}] \p{Alnum} [:alpha:] Alphabetic characters …

    Linux干货 2017-07-07
  • 字符切割和用户管理

    1、列出当前系统上所有已经登录的用户的用户名,同一个用户登录多次,则只显示一次 who |cut -d’ ‘ -f1 |sort -u2、取出最后登录到当前系统的用户的相关信息。 last |head -1|cut -d’ ‘ -f1 3、取出当前系统上被用户当作其默认shell的最多的那个shell。 cut…

    2017-12-17