统计出/etc/passwd文件中其默认shell为/sbin/nologin的用户个数,并将用户都显示出来
root@CentOS7[16:06:27]:~# cat /etc/passwd | grep "/sbin/nologin" | wc -l
40
root@CentOS7[16:06:27]:~# cat /etc/passwd | grep "/sbin/nologin" | cut -d ":" -f 1
...
由于结果太长估省略
查出用户UID最大值的用户名、UID及shell类型
sort -t ":" -nr -k 3 /etc/passwd | cut -d ":" -f 1,3,7 | head -n 1
统计当前连接本机的每个远程主机的IP的连接数,并按从大到小排序
netstat -net|egrep [0-9]|tr -s " " :|cut -d: -f6|sort |uniq -c|sort -r
编写脚本createuser.sh,实现如下功能
1、使用一个用户名作为参数
2、如果指定参数的用户存在,显示 “存在” ,否则添加之
3、显示添加用户的id号等信息
#!/bin/bash
#判断是否传入位置变量
[ $# = 0 ] && echo "执行脚本时后面跟上要添加的用户名名称" && exit 1
new_username=$1
#判断用户是否已经添加
if ! grep "^${new_username}\>" /etc/passwd &>/dev/null; then
useradd $new_username &>/dev/null
echo "$new_username 用户已经添加成功"
else
echo "$new_username 用户已经存在"
id $new_username
fi
编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
vim ~/.vimrc 或者 vim /etc/vimrc(在文件最下方添加以下内容)
#author_name 自定义内容
#author_email 自定义内容
#file_description 自定义内容
#=======================================================================================================
autocmd BufNewFile *.sh, exec ":call SetTitle()"
let $author_name = "lyvin"
let $author_email = "xxxx@163.com"
let $file_description = "A little every day"
func SetTitle()
call setline(1,"\###################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: ".$author_name)
call append(line(".")+2, "\# mail: ".$author_email)
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\# File description: ".$file_description)
call append(line(".")+5, "\####################################################################")
call append(line(".")+6, "\#!/bin/bash")
call append(line(".")+7, "")
endfunc
#=======================================================================================================
vim new_file.sh
使用vim创建*.sh的文件的时候就可以看到自动添加的内容了,如下图

new_file.sh