第四周 文本处理工具

1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
grep -v "/sbin/nologin$" /etc/passwd|cut -d: -f 1
2、查出用户UID最大值的用户名、UID及shell类型
sort -t: -k 3 -nr /etc/passwd |head -1 |cut -d: -f 1,3,7|tr ":" " "
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
ss -nt |grep "ESTAB"|tr -s " " : |cut -d" " -f 6 |sort -nr
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
1)短路与、或方式实现
id $1 &>/dev/null && echo "The $1 already exists" || useradd $1
2)if方式实现
if id $1 &>/dev/null;then
echo "The $1 already exists"
else
useradd $1
exit 1
fi
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
修改 vimrc 文件
全局:/etc/vimrc
个人:~/.vimrc

set cursorline
set hlsearch
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: 2hs")
call setline (5,"#QQ: 962248453")
call setline (6,"#Date: ".strftime("%Y-%m-%d"))
call setline (7,"#FileName: ".expand("%"))
call setline (8,"#Description: The test script")
call setline (9,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline (10,"#****")
call setline (11,"")
endif
endfunc
autocmd BufNewFile * normal G

猜你喜欢

转载自blog.51cto.com/h880515/2467067
今日推荐