1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@centos7 ~]#cat /etc/passwd |grep -v /sbin/nologin$
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
xia:x:1000:1000:xia:/home/xia:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2019::/home/slackware:/bin/tcsh
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos7 ~]#sort -t: -k3 -nr /etc/passwd |head -n1 |cut -d: -f1,3,7
nfsnobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos7 /data]#ss -nt|grep ^ESTAB |cut -d":" -f1 |tr -s " " |cut -d" " -f4 |uniq -c |sort -nr
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
[root@centos7 /data]#vim createuser.sh
#!/bin/bash
id $1 &> /dev/null
[[ $? -eq 0 ]] && echo the user exist. || (useradd $1 >/dev/null; id $1)
[root@centos7 /data]#bash createuser.sh xia
the user exist.
[root@centos7 /data]#id han
id: han: no such user
[root@centos7 /data]#bash createuser.sh han
uid=2003(han) gid=2003(han) groups=2003(han)
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
vim .vimrc
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"#")
call setline(3,"#********************************************************************")
call setline(4,"#Author: xiahanhan")
call setline(5,"#QQ: 1121311496")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: http://www.magedu.com")
call setline(9,"#Description: The test script")
call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#********************************************************************")
call setline(12,"")
endif
endfunc
autocmd BufNewFile * normal G
编辑好的.vimrc文件放在家目录或者/etc/目录下,对当前用户或者所有用户有效。