1, 列出当前系统上所有已经登陆的用户的用户名, 注意: 同一个用户登陆多次, 则只显示一次即可
who |cut -d"" -f1 | sort -u
2, 列出最后登陆到当前系统的用户的相关信息
who | tail -1
3, 取出当前系统上被用户当作其默认 shell 的最多的那个 shell
cat /etc/passwd | cut -d : -f7 | uniq -c |sort -n |tail -1
4, 将 / etc/passwd 中的第三个字段数值最大的后 10 个用户的信息全部改为大写后保存至 / tmp/maxusers.txt 文件中
cat /etc/passwd | sort -t : -k 3 -n | tail -10 | tr 'a-z' 'A-Z'> /tmp/maxusers.txt
5, 取出当前主机的 IP 地址, 提示: 对 ifconfig 命令的结果进行切分
ifconfig | grep inet|cut -d " " -f10 |head -1
6, 列出 / etc 目录下所有以. conf 结尾的文件的文件名, 并将其名字转换为大写后保存至 / tmp/etc.conf 文件中
ls /etc/*.conf | tr 'a-z' 'A-Z'> /tmp/etc.conf
7, 显示 / var 目录下一级子目录或文件的总个数
ls /var |wc -l
8, 取出 / etc/group 文件中第三个字段数值最小的 10 个组的名字
cat /etc/group | sort -t : -k 3| 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
groupadd -g 2016 distro
2), 创建用户 mandriva, 其 ID 号为 1005; 基本组为 distro
useradd -u 1005 -g distro mandriva
3), 创建用户 mageia, 其 ID 号为 1100, 家目录为 / home/linux
useradd -u 1100 -d /home/linux mageia
4), 给用户 mageia 添加密码, 密码为 mageedu
echo mageedu | passwd -stdin mageia
5), 删除 mandriva, 但保留其家目录
userdel mandriva
6), 创建用户 slackware, 其 ID 号为 2002, 基本组为 distro, 附加组为 peguin
useradd -u 2002 -g distro -G peguin slackware
7), 修改 slackware 的默认 shell 为 / bin/tcsh
usermod -s /bin/tcsh slackware
8), 为用户 slackware 新增附加组 admins
usermod -aG admins slackware
来源: http://www.bubuko.com/infodetail-2751803.html