1、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息

脚本内容: [root@CentOS8 script]#vim createuser.sh #!/bin/bash ############################################## #File Name: createuser.sh #Version: V1.0 #Author: LiRui #Created Time: 2020-12-28 10:55:42 #Description: The test script ############################################# USER=$1 if [ -n "$USER" ];then if id "$USER" &>/dev/null;then echo "$USER is exit" else useradd $USER &>/dev/null && echo "add $USER" && id $USER
fi else echo "请输入用户名!" fi

执行结果: [root@CentOS8 script]#./createuser.sh xiaoming 已经存在的用户作为参数 xiaoming is exit [root@CentOS8 script]#./createuser.sh xiaohua 不存在的用户作为参数 add xiaohua uid=1008(xiaohua) gid=1012(xiaohua) groups=1012(xiaohua) [root@CentOS8 script]#./createuser.sh 没有带参数 请输入用户名!

2、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等

在root用户家目录/root下,创建.vimrc文件,内容如下: [root@CentOS8 ~]#vim .vimrc set cul "在Shell脚本开头自动增加解释器及作者等版权信息" autocmd BufNewFile *.sh exec ":call SetTitle()" func SetTitle() if expand("%:e") == 'sh' call setline(1, "#!/bin/bash") call setline(2, "##############################################") call setline(3, "#File Name: ".expand("%")) call setline(4, "#Version: V1.0") call setline(5, "#Author: LiRui") call setline(6, "#Created Time: ".strftime("%F %T")) call setline(7, "#Description: The test script") call setline(8, "##############################################") call setline(9, "")
endif endfunc "新建文件后,自动定位到文件末尾" autocmd BufNewFile * normal G

3、查找/etc目录下大于1M且类型为普通文件的所有文件

find /etc -size +1M -type f |xargs du -sh

4、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷到/usr/local/src目录备份。

find /etc -size +1M -type f |xargs tar cf /data/test/date +%F &>/dev/null && cp /data/test/date +%F /usr/local/src

5、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录

find / ( -nouser -o -nogroup ) -atime -7

6、查找/etc目录下至少有一类用户没有执行权限的文件

find /etc -type f -not -perm -111